阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Centos7默认firewalld防火墙使用命令

31次阅读
没有评论

共计 1971 个字符,预计需要花费 5 分钟才能阅读完成。

导读 Centos7 默认的 firewalld 防火墙说实话真不好用,不如使用 iptables。但一物的存在是有它的道理,比如在高级功能方面 iptables 就要次于 firewalld 防火墙,所以建议大家还是要追随主流,现在开源产品相对过去的版本更新很快,所以要跟得上脚步,特别是对于运维人员来讲。下面是我平时在生产环境当中维护机器常用到的,大家可以参考下。

Centos7 默认 firewalld 防火墙使用命令

基本操作;

# systemctl start firewalld // 启动
 # systemctl status firewalld // 状态
 # systemctl disable firewalld // 禁用
 # systemctl stop firewalld // 停止 

systemctl 在 centos7 中必不可缺少的管理工具,它具备 service 和 chkconfig 的所有功能;

# systemctl start firewalld.service // 启动某个服务
 # systemctl stop firewalld.service // 关闭某个服务
 # systemctl restart firewalld.service // 重启某个服务
 # systemctl status firewalld.service // 显示某个服务的状态
 # systemctl enable firewalld.service // 开机时随机自启动
 # systemctl disable firewalld.service // 禁止开机启动
 # systemctl is-enabled firewalld.service // 查看是否开机启动
 # systemctl list-unit-files|grep enabled // 查看已经启动的服列表
 # systemctl --failed // 查看启动失败的服务列表 

基本配置 firewalld-cmd;

# firewall-cmd --version // 查看防火墙版本
 # firewall-cmd --help // 查看命令操作帮助
 # firewall-cmd --state // 显示当前状态
 # firewall-cmd --zone=public --list-ports // 查看所有打开运行的端口
 # firewall-cmd --reload // 不重启立即加载
 # firewall-cmd --list-all-zones | more // 查看区域信息情况
 # firewall-cmd --get-zone-of-interface=eth0 // 查看指定接口所属区域
 # firewall-cmd --panic-on // 拒绝所有包
 # firewall-cmd --panic-off // 取消拒绝状态
 # firewall-cmd --query-panic // 查看是否拒绝 

举个例子,如何打开一个端口,例如 3306;

# firewall-cmd --zone=public --add-port=3306/tcp --permanent // 添加 3306 端口(--permanent)永久生效,没有此参数重启后失效
 # firewall-cmd --reload // 不重启立即加载
 # firewall-cmd --zone= public --query-port=3306/tcp // 查看加入 3306 端口状态
 # firewall-cmd --zone= public --remove-port=3306/tcp --permanent // 删除刚刚加入的防火墙规则 3306
 # firewall-cmd --permanent --remove-icmp-block=echo-request // 删除禁 ping
 # firewall-cmd --permanent --add-icmp-block=echo-request // 开启禁 ping
 # firewall-cmd --get-service // 查看已被允许的信息 

具体的规则管理,可以使用 firewall-cmd,具体的使用方法可以

# firewall-cmd --help

firewall-cmd 高级功能可以到官方资料库了解更多信息。

https://fedoraproject.org/wiki/FirewallD/zh-cn

https://access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html

https://www.ibm.com/developerworks/cn/linux/1507_caojh/

注意:以上操作方法以及命令并不适用于 Centos7 以下版本, 除你在其他 linux 发行版单独安装 firewall 的。

阿里云 2 核 2G 服务器 3M 带宽 61 元 1 年,有高配

腾讯云新客低至 82 元 / 年,老客户 99 元 / 年

代金券:在阿里云专用满减优惠券

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2024-07-24发表,共计1971字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中