firewall-cmd 常用命令

klvchen發表於2018-12-04
# 開啟防火牆
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