#更改默认区域为work
firewall-cmd --set-default-zone=work
#在默认区域放行80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
#默认区域禁用80端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent
#默认区域禁止ping包
firewall-cmd --zone=public --add-icmp-block=echo-request --permanent
#默认区域添加协议
firewall-cmd --zone=public --add-protocol=icmp –permanent
#在work区域放行某个网段
firewall-cmd --zone=work --add-source=10.20.30.0/8 --permanent
#在work区域放行8443端口
firewall-cmd --zone=work --add-port=8443/tcp --permanent
#drop区域允许ping包
firewall-cmd --zone=drop --permanent --add-rich-rule='rule protocol value=icmp accept'
#放行某个IP允许访问某个端口
firewall-cmd --zone=drop --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="22" accept"
#放行某个IP段允许访问某个端口
firewall-cmd --zone=drop --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.1/24" port protocol="tcp" port="22" accept"
#在默认区域放行某个ip的某个端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address=" 118.186.200.164 " port protocol="tcp" port="4000-5000" accept"
#IP封禁
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.222' reject" 拒绝单个IP
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.0/24' reject" 拒绝IP段
#端口转发
要打开端口转发,则需要先 firewall-cmd --zone=public --add-masquerade
#然后转发 tcp 22 端口至 3753
firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=3753
#转发 22 端口数据至另一个 ip 的相同端口上
firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100
#转发 22 端口数据至另一 ip 的 2055 端口上
firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100
#删除 rule (--remove-rich-rule='rule')
firewall-cmd --permanent --zone=drop --remove-rich-rule='rule family="ipv4" source address="192.168.1.1/32" port port="9024" protocol="tcp" accept'
#针对某个IP开放所有端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="103.93.180.231" port protocol="udp" port="1-65535" accept"
#添加端口映射 10.0.197.189的5432端口映射到本机5432端口
firewall-cmd --add-forward-port=port=5432:proto=tcp:toaddr=10.0.197.189:toport=5432 --permanent
#删除地址转发
firewall-cmd --permanent --remove-forward-port=port=8080:proto=tcp:toport=8080:toaddr=10.10.10.201
#白名单设置(允许这个段所有网络连接)
firewall-cmd --permanent --zone=truted --add-source=10.10.10.0/24
#查看所有区域开放的端口及服务
firewall-cmd --list-all
#查看一个区域开放的服务
firewall-cmd --zone=public --list-services
#查看一个区域开放的接口
firewall-cmd --zone=public --list-interfaces
#获取所有支持的服务
firewall-cmd --get-services