开启防火墙
shell
systemctl start firewalld
关闭防火墙
shell
systemctl stop firewalld # 暂时关闭防火墙
systemctl disable firewalld # 永久关闭防火墙(禁用开机自启)
systemctl enable firewalld # 永久开启防火墙(启用开机自启)
重启防火墙
shell
systemctl restart firewalld
重载规则
shell
firewall-cmd --reload
查看已配置规则
shell
firewall-cmd --list-all
防火墙端口开放
shell
firewall-cmd --zone=public --add-port=5672/tcp --permanent # 开放5672端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent #关闭5672端口
firewall-cmd --reload # 配置立即生效
查看防火墙所有开放的端口
shell
firewall-cmd --zone=public --list-ports
指定端口和ip访问
shell
firewall-cmd --permanent --add-rich-rule="rule famil="ipv4" source address="192.168.137.139" port protocol="tcp" port="8080" accept"
移除指定端口和ip访问
shell
firewall-cmd --permanent --remove-rich-rule="rule famil="ipv4" source address="192.168.137.139" port protocol="tcp" port="8080" accept"