1 防火墙 - firewalld
1.1 开启防火墙
systemctl start firewalld
systemctl enable firewalld
1.2 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
1.3 重启防火墙
systemctl restart firewalld
1.4 查看防火墙状态
systemctl status firewalld
firewall-cmd --state
1.5 重载防火墙配置
firewall-cmd --reload
2 区域 - zone
2.1 查看所有可用的区域
firewall-cmd --get-zones
2.2 查看当前激活的区域
firewall-cmd --get-active-zones
2.3 查看指定区域的详细信息
firewall-cmd --zone = public --list-all
firewall-cmd --list-all
2.4 查看默认区域
firewall-cmd --get-default-zone
2.5 设置默认区域
firewall-cmd --set-default-zone= public
2.6 添加区域
firewall-cmd --permanent --new-zone= myzone
2.7 删除区域
firewall-cmd --permanent --delete-zone= myzone
2.8 分配网络接口到指定区域
firewall-cmd --zone = public --change-interface= eth0
3 端口 - port
3.1 查看已开放的端口
firewall-cmd --list-ports
firewall-cmd --zone = public --list-ports
3.2 添加指定开放端口
firewall-cmd --permanent --add-port= 3306 /tcp
firewall-cmd --permanent --add-port= 9000 -9008/tcp
firewall-cmd --zone = public --permanent --add-port= 3306 /tcp
firewall-cmd --zone = public --permanent --add-port= 9000 -9008/tcp
3.3 移除指定开放端口
firewall-cmd --permanent --remove-port= 3306 /tcp
firewall-cmd --permanent --remove-port= 9000 -9008/tcp
firewall-cmd --zone = public --permanent --remove-port= 3306 /tcp
firewall-cmd --zone = public --permanent --remove-port= 9000 -9008/tcp
3.4 查询指定开放端口
firewall-cmd --query-port= 3306 /tcp
firewall-cmd --zone = public --query-port= 3306 /tcp
4 服务 - service
4.1 查看已启用的服务
firewall-cmd --list-services
firewall-cmd --zone = public --list-services
4.2 查看所有可用的服务
firewall-cmd --get-services
4.3 查看指定防火墙规则
firewall-cmd --info-service= ssh
4.4 添加指定服务
firewall-cmd --permanent --add-service= http
firewall-cmd --zone = public --permanent --add-service= http
4.5 移除指定服务
firewall-cmd --permanent --remove-service= http
firewall-cmd --zone = public --permanent --remove-service= http
5 富规则 - rich-rule
5.1 查看已设置的富规则
firewall-cmd --list-rich-rules
firewall-cmd --zone = public --list-rich-rules
5.2 添加规则
firewall-cmd --permanent --add-rich-rule= "rule family=" ipv4" source address=" 192.168 .198.200" port protocol=" tcp" port=" 3306 " accept"
firewall-cmd --permanent --add-rich-rule= "rule family=" ipv4" source address=" 192.168 .198.200" port protocol=" tcp" port=" 3306 " reject"
firewall-cmd --zone = public --permanent --add-rich-rule= "rule family=" ipv4" source address=" 192.168 .198.200" port protocol=" tcp" port=" 3306 " accept"
firewall-cmd --zone = public --permanent --add-rich-rule= "rule family=" ipv4" source address=" 192.168 .198.200" port protocol=" tcp" port=" 3306 " reject"
5.3 移除规则
firewall-cmd --permanent --remove-rich-rule= "rule family=" ipv4" source address=" 192.168 .198.200" port protocol=" tcp" port=" 3306 " accept"
firewall-cmd --zone = public --permanent --remove-rich-rule= "rule family=" ipv4" source address=" 192.168 .198.200" port protocol=" tcp" port=" 3306 " accept"
6 注意事项
--permanent
参数会将修改的防火墙配置永久性保存到防火墙配置文件中;修改防火墙配置时如果没有使用该参数则会在系统重启时丢失修改的配置。