systemctl restart firewalld //重启防火墙
firewall-cmd --reload //重新加载防火墙配置
systemctl start firewalld.service //开启服务
systemctl enable firewalld.service //开机制动启动
systemctl stop firewalld.service //关闭服务
systemctl disable firewalld.service //禁止开机启动
例子:
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --reload
–add-service #添加的服务
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
在每次修改 端口和服务后 /etc/firewalld/zones/public.xml 文件就会被修改 所以也可以在文件中之间修改 然后重新加载
firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.0.4/24" service name="http" accept"//设置某个ip 访问某个服务
firewall-cmd --permanent --zone=public --remove-rich-rule="rule family="ipv4" source address="192.168.0.4/24" service name="http" accept" //删除配置
firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=192.168.0.1/2 port port=80 protocol=tcp accept' //设置某个ip访问某个端口
firewall-cmd --permanent --remove-rich-rule 'rule family=ipv4 source address=192.168.0.1/2 port port=80 protocol=tcp accept' //删除配置
firewall-cmd --query-masquerade # 检查是否允许伪装IP
firewall-cmd --add-masquerade # 允许防火墙伪装IP
firewall-cmd --remove-masquerade# 禁止防火墙伪装IP
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 # 将80端口的流量转发至8080
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.1.0.1 # 将80端口的流量转发至192.168.0.1
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.0.1:toport=8080 # 将80端口的流量转发至192.168.0.1的8080端口
firewall-cmd –state //获取 firewalld 状态
firewall-cmd –state && echo “Running” || echo “Not running” //状态输出
firewall-cmd –reload //重新加载防火墙
firewall-cmd –get-zones //获取支持的区域列表
firewall-cmd –get-services //获取所有支持的服务
firewall-cmd –list-all-zones //列出全部启用的区域的特性
firewall-cmd [–zone=] –add-interface= //将接口增加到区域
firewall-cmd [–zone=] –change-interface= //修改接口到区域
firewall-cmd [–zone=] –remove-interface= //删除接口到区域
firewall-cmd [–zone=] –query-interface= //查询区域中的接口