centos7防火墙常用命令
查看状态
firewall-cmd --state
systemctl status firewalld.service
启用防火墙
systemctl enable firewalld.service
或者
systemctl start firewalld
关闭防火墙
systemctl stop firewalld
开放一个端口(22)对任意IP访问的权限
firewall-cmd --zone=public --add-port=22/tcp --permanent
针对某个IP(192.168.102.2)开放某个端口(5601)的访问权限
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.102.2" port protocol="tcp" port="5601" accept"
重新加载防火墙规则
firewall-cmd --reload
查看对任意IP开放访问的端口
firewall-cmd --permanent --list-port
查看所有规则
firewall-cmd --list-all
删除某个端口规则(5601端口为例i)
firewall-cmd --zone=public --remove-port=5601/tcp --permanent
屏蔽一个IP
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=1.1.1.1 reject'
删除一个屏蔽IP的规则
firewall-cmd --remove-rich-rule 'rule family=ipv4 source address=1.1.1.1 reject' --permanent