1.查看防火墙状态
systemctl status firewalld
2.开启,关闭和重启防火墙
sudo systemctl start firewalld
sudo systemctl stop firewalld
sudo systemctl restart firewalld
3.开机启用或禁用防火墙
sudo systemctl disable firewalld
sudo systemctl enable firewalld
4.查看防火墙现有规则
sudo firewall-cmd --list-all
5.查询,开放和关闭端口
查询端口是否开放,返回yes或者no。
sudo firewall-cmd --query-port=80/tcp
开放单个端口(临时,重启防火墙失效)
sudo firewall-cmd --add-port=8080/tcp
开放单个端口(永久,需重启后生效)
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
开放范围端口
sudo firewall-cmd --permanent --add-port=39000-40000/tcp
sudo firewall-cmd --reload
关闭端口
sudo firewall-cmd --permanent --remove-port=39000-40000/tcp
sudo firewall-cmd --reload
6.较为复杂的规则设置
为指定的IP设置端口开放
sudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='192.168.1.201' port protocol='tcp' port='5672' accept"