centos7添加firewalld规则

#允许192.168.142.166访问5432端口
[root@henry ~]# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept" --permanent 
#允许所有IP访问80端口 --permanent 表示永久生效,不加重启就会失效
[root@henry ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent 
#删除某条规则
[root@henry ~]# firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="11300" accept"
#查看规则
[root@henry ~]# firewall-cmd --list-all
#每次修改规则之后都要重启firewalld才会生效
[root@henry ~]# systemctl restart firewalld 
原文地址:https://www.cnblogs.com/kjjmj/p/13277128.html