防火牆是系統安全第一道防線,但測試、調試或特定服務部署時常需臨時關閉。本文涵蓋 CentOS/RHEL(iptables、firewalld)、Fedora、Ubuntu(ufw/iptables)等主流發行版的臨時關閉與永久關閉方法,並強調生產環境操作風險與最佳實踐。
| 類型 | 開啟 | 關閉 |
|---|---|---|
| 永久(重啟生效) | chkconfig iptables on | chkconfig iptables off |
| 即時(重啟失效) | service iptables start | service iptables stop |
| 類型 | 命令 |
|---|---|
| 查看狀態 | firewall-cmd --state / systemctl status firewalld |
| 即時關閉 | systemctl stop firewalld |
| 永久關閉 | systemctl disable firewalld |
| 開放端口(永久) | firewall-cmd --permanent --add-port=80/tcp && firewall-cmd --reload |
ufw enableufw disableufw allow 22/tcpufw status numbered安全關閉步驟(避免默認 DROP 鎖死 SSH):
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F # 清空所有規則
iptables -X # 刪除用戶自定義鏈
保存規則: iptables-save > /etc/iptables/rules.v4(需安裝 iptables-persistent)
Root 下執行 setup → Firewall configuration → Security Level 選 Disabled → 保存重啟。
iptables -F: 若默認鏈策略為 DROP,清空規則會阻斷所有連接(含 SSH)。ferm、shorewall 等高層工具。