Linux firewall 常用命令,


linux firewall防火墙放行端口

firewall-cmd --zone=public --add-port=xxxx/tcp --permanent
  • --zone 作用域
  • --permanent 永久生效,没有此参数重启后失效

firewalld刷新生效

firewall-cmd --reload

查看所有放行端口

firewall-cmd --zone=public --list-ports

禁止IP访问机器

firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="192.168.0.1" drop'

禁止一个IP段,比如禁止192.168..

firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="192.168.0.1/16" drop'

禁止一个IP段,比如禁止192.168.0.*

firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="192.168.0.1/24" drop'

禁止机器IP从防火墙中删除

firewall-cmd --permanent --remove-rich-rule='rule family=ipv4 source address="192.168.0.1" drop'

允许http服务(对应服务策略目录:/usr/lib/firewalld/services/)

firewall-cmd --permanent --add-service=http

关闭http服务(对应服务策略目录:/usr/lib/firewalld/services/)

firewall-cmd --permanent --remove-service=http

允许端口:3306

firewall-cmd --permanent --add-port=3306/tcp

允许端口:1-3306

firewall-cmd --permanent --add-port=1-3306/tcp

关闭放行中端口:3306

firewall-cmd --permanent --remove-port=3306/tcp

查看firewall的状态

firewall-cmd --state

查看防火墙规则(只显示/etc/firewalld/zones/public.xml中防火墙策略)

firewall-cmd --list-all

查看所有的防火墙策略(即显示/etc/firewalld/zones/下的所有策略)

firewall-cmd --list-all-zones

重新加载配置文件

firewall-cmd --reload

相关内容