![給出 iptables -F 後無法到達主機](https://rvso.com/image/768905/%E7%B5%A6%E5%87%BA%20iptables%20-F%20%E5%BE%8C%E7%84%A1%E6%B3%95%E5%88%B0%E9%81%94%E4%B8%BB%E6%A9%9F.png)
試圖清除我的 RedHat Linux 伺服器中的防火牆設定。
給出後iptables -F
,我無法訪問伺服器。
# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:diamondport
ACCEPT tcp -- anywhere anywhere tcp dpt:33336
ACCEPT sctp -- anywhere anywhere sctp dpts:1024:65535
ACCEPT udp -- anywhere anywhere udp dpt:gtp-user
ACCEPT udp -- anywhere anywhere udp dpts:6000:lm-x
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
# iptables -F
請幫我解決這個問題。
答案1
當您執行 iptables -F 時,您將刪除每個鏈中的每個規則。然而,每條鏈都有一個政策您不是在刪除,在您的情況下是 INPUT 鏈的 DROP。因此,您將刪除所有規則並對任何不匹配規則的流量套用 DROP 策略,這表示所有內容都會被丟棄。
您可以透過執行:iptables -L -n 來確認這一點。你應該看到這樣的東西:
Chain INPUT (policy DROP)
target prot opt source destination
[it's empty]
這是正常行為。您可以更改預設策略,但這會導致安全性方面完全不同的行為:如果沒有匹配的規則,流量將始終被接受,這可能不是您想要的。
最好的方法是在修改 iptables 策略以使它們持久使用時避免刷新和保存它們iptables-save
。這樣,您可以保存先前的配置並iptables-restore < rules.bak
根據需要恢復它( )或修改它。
答案2
控制台重新啟動後即可存取主機。謝謝