CentOS常用防火墙命令

systemctl启动、停止、查看防火墙状态

systemctl从CentOS7.x开始引入的一个服务管理工具命令,集 service和chkconfig的功能于一体。

  1. 启动防火墙
systemctl start firewalld
  1. 停止防火墙
systemctl stop firewalld
  1. 重启防火墙
systemctl restart firewalld
  1. 查看防火墙状态
systemctl status firewalld

service启动、停止、查看防火墙状态

  1. 启动防火墙
service iptables start 
  1. 查看防火墙状态
service iptables status 
  1. 关闭防火墙
service iptables stop 
  1. 重启防火墙
service iptables restart 
  1. 永久关闭防火墙
chkconfig iptables off 
  1. 永久关闭后开启防火墙
chkconfig iptables on 

端口放行

  1. 查看所有放行端口
firewall-cmd --zone=public --list-ports
  1. 放行端口:8161
firewall-cmd --permanent --add-port=8161/tcp
  1. 重启防火墙(重新加载配置文件)

更改配置后一定要重新加载配置文件

firewall-cmd --reload
  1. 查看firewall的状态
firewall-cmd --state 
  1. 禁止IP访问机器
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="192.168.0.1" drop'
  1. 禁止一个IP段,比如禁止192.168..
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="192.168.0.1/16" drop'
  1. 禁止机器IP从防火墙中删除
firewall-cmd --permanent --remove-rich-rule='rule family=ipv4 source address="192.168.0.1" drop'
  1. 允许http服务(对应服务策略目录:/usr/lib/firewalld/services/)
firewall-cmd --permanent --add-service=http
  1. 允许端口(范围):1-3306
firewall-cmd --permanent --add-port=1-3306/tcp
  1. 关闭放行中端口:8161
firewall-cmd --permanent --remove-port=8161/tcp
  1. 查看防火墙规则(只显示/etc/firewalld/zones/public.xml中防火墙策略)
firewall-cmd --list-all
  1. 查看所有的防火墙策略(即显示/etc/firewalld/zones/下的所有策略)
firewall-cmd --list-all-zones
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shexianyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值