1.查看当前默认区域
firewall-cmd --get-default-zone
2.查看当前正在活动的区域
firewall-cmd --get-active-zones
3.防火墙规则列表
firewall-cmd --list-all
4.放行端口
firewall-cmd --add-port=8080/tcp --add-port=8080/udp
firewall-cmd --add-port={8081,8082}/tcp
firewall-cmd --add-port={8090..8095}/tcp
5.删除放行的端口
firewall-cmd --remove-port={8090..8095}/tcp
6.放行服务
firewall-cmd --add-service=http
7.自定义服务名称
cd /usr/lib/firewalld/services/
cp http.xml nginx.xml
firewall-cmd --reload'
firewall-cmd --add-service=nginx
8.防火墙转发规则 (四层负载)
firewall-cmd --permanent --zone=<区域> --add-forward-port=port=<源端口号>:proto=<协议>:toport=<目标端口号>:toaddr=<目标IP地址>
firewall-cmd --add-forward-port=port=5555:proto=tcp:toport=22:toaddr=172.16.1.7
firewall-cmd --add-masquerade
9.Firewalld 富规则
man firewall-cmd
man firewalld.richlanguage
rule
[source]
[destination]
service|port|protocol|icmp-block|masquerade|forward-port
[log]
[audit]
[accept|reject|drop]
rule [family="ipv4|ipv6"]
source address="address[/mask]" [invert="True"]
service name="service name"
port port="port value" protocol="tcp|udp"
forward-port port="port value" protocol="tcp|udp" to-port="port value" to-addr="address"
accept | reject [type="reject type"] | drop
firewall-cmd --add-rich-rule='rule family=ipv4 source address=10.0.0.1/32 port port="80" protocol="tcp" accept'
firewall-cmd --add-rich-rule='rule family=ipv4 source address=172.16.1.0/24 port port="8081" protocol="tcp" accept
firewall-cmd --add-rich-rule='rule family=ipv4 source address="172.16.1.0/24" service name="ssh" drop'
firewall-cmd --remove-service=ssh
firewall-cmd --add-service={http,https}
firewall-cmd --add-rich-rule='rule family=ipv4 source address="10.0.0.1/32" service name="ssh" accept'
firewall-cmd --add-rich-rule='rule family=ipv4 source address="10.0.0.1/32" forward-port port="6666" protocol="tcp" to-port="22" to-addr="172.16.1.7"'
firewall-cmd --add-masquerade
10.Firewalld 实现共享上网
(1) 开启共享上网
firewall-cmd --add-masquerade
(2)客户端将默认网关指向---> 能上网的地址
[root@web01 ~]
IPADDR=172.16.1.7
GATEWAY=172.16.1.61
DNS1=223.5.5.5
PREFIX=24
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步