
我想在節點內部的 iptables 上製定一組規則,但 iptables 似乎沒有附加所有規則或以某種方式在每次運行以下腳本時將我踢出(我在其他伺服器並且工作正常):
# Allow connections that are already connected to your server
iptables -A INPUT -i venet0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow connections to SSH
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
# Allowing connections to HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT
# Allow icmp input but limit it to 10/sec
iptables -A INPUT -p icmp -m limit --limit 10/second -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
# Allow all incoming traffic from local
iptables -A INPUT -i lo -j ACCEPT
# Changing the default policy for INPUT chain
iptables -A INPUT -j DROP
我發現的問題(我猜)是最後一行(DROP everything)被解釋為一個,這就是伺服器將我踢出的原因。
我已經更改了 vz 的conf:
IPTABLES_MODULES="ipt_REJECT ipt_tos ipt_limit ipt_multiport iptable_filter iptable_mangle ipt_TCPMSS ipt_tcpmss ipt_ttl ipt_length ipt_state xt_state ip_conntrack"
如有任何幫助,我們將不勝感激。
謝謝。
答案1
我在 OpenVZ 和使用「ESTABLISHED,RELATED」時看到了更多問題。遺憾的是,我無法找到如何修復由於某種原因不允許在容器中使用有狀態 iptables 的 OpenVZ 安裝。
但是,對於您擁有的相當簡單的 IPTable 規則,您真的需要它們是有狀態的嗎?我認為以下內容同樣有效:
# Allow connections to SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allowing connections to HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Allow icmp input but limit it to 10/sec
iptables -A INPUT -p icmp -m limit --limit 10/second -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
# Allow all incoming traffic from local
iptables -A INPUT -i lo -j ACCEPT
# Changing the default policy for INPUT chain
iptables -A INPUT -j DROP