開啓防火牆
systemctl start firewalld.service
開機自啓
systemctl enable firewalld.service
關閉防火牆
systemctl stop firewalld.service
查看防火牆狀態
firewall-cmd --state
查看現有規則
iptables -nL
firewall-cmd --zone=public --list-ports
新建ZONE
firewall-cmd --per --new-zone=tailscale
設置默認ZONE
firewall-cmd --set --default-zone=zone
將指定網卡加入到ZONE
firewall-cmd --zone=public --add-inter
重載防火牆
firewall-cmd --reload
添加單個端口
firewall-cmd --permanent --zone=public --add-port=81/tcp
添加多個端口
firewall-cmd --permanent --zone=public --add-port=8080-8083/tcp
刪除指定端口
firewall-cmd --permanent --zone=public --remove-port=81/tcp
允許指定ip訪問指定端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.2.166" port protocol="tcp" port="3306" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.123.3" accept"
刪除指定IP
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.51" accept"
允許指定IP段訪問
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="9200" accept"
端口轉發
firewall-cmd --permanent --zone=<區域> --add-forward-port=port=<源端口號>:proto=<协议>:toport=<目標端口號>:toaddr=<目標IP地址>
firewall-cmd --per --add-masquerade # 開啓僞裝
# 轉發本地12380端口到遠程服務器的22855端口
firewall-cmd --zone=public --add-forward-port=port=12380:proto=tcp:toport=22855:toaddr=10.3.7.2 --permanent
拒絕指定IP段的ICMP
firewalld-cmd --per --add-rich-rule 'rule faimly=ipv4 source address=192.168.31.1/24 protocol=icmp reject'
禁止ICMP
firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'
iptables -A OUTPUT -d 3.15.61.25 -j DROP
拒絕指定IP/段訪問指定端口/服務
firewalld --per --add-rich-rule 'rule faimly=ipv4 source address=192.168.31.1/24 protocol=tcp port port=20-22 drop