``` # 開啟防火牆 systemctl start firewalld.service # 防火牆開機啟動 systemctl enable firewalld.service # 關閉防火牆 systemctl stop firewalld.service # 查看防火牆狀態 firewall... ...
# 開啟防火牆
systemctl start firewalld.service
# 防火牆開機啟動
systemctl enable firewalld.service
# 關閉防火牆
systemctl stop firewalld.service
# 查看防火牆狀態
firewall-cmd --state
# 查看現有的規則
iptables -nL
# 重載防火牆配置
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.142.166" port protocol="tcp" port="6379" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.233" 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 --reload