iptables 阻止 PPP0 上除一个端口之外的所有端口

iptables 阻止 PPP0 上除一个端口之外的所有端口

我有 2 个 dsl 帐户。一个是在我的路由器上设置的通用帐户,另一个是在服务器上设置的。我的路由器的安全性很好,但我注意到在我的服务器上设置 PPPoe 后,路由器的安全性被完全绕过,并且我的服务器上的所有端口基本上都向全世界开放。

所以我尝试阻止 PPP 上的所有连接

iptables -A INPUT -i ppp0 -p tcp -j DROP
iptables -I INPUT -i ppp0 -p tcp --dport 563 -j ACCEPT

但是现在我无法连接到端口 563。

我怀疑我从根本上误解了 iptables 的工作原理。

答案1

顺序很重要!你没有走错路,但你需要改变顺序。先把 ACCEPT 放上去,然后再把 REJECT 放上去,这样就没问题了。

答案2

您需要设置一些默认规则,然后为其余规则制定策略。这是一个很好的起点:

iptables -A INPUT --match state --state RELATED,ESTABLISHED -j ACCEPT --match comment --comment "Accept traffic from outgoing connections and stuff like FTP."
iptables -A INPUT -p icmp -j ACCEPT --match comment --comment "Allow ping"
iptables -A INPUT -p tcp --dport 22 -j ACCEPT --match comment --comment "Allow SSH"
iptables -A INPUT --in-interface lo -j ACCEPT --match comment --comment "Allow everything on the localhost"
iptables -P INPUT DROP

然后您可以添加您的规则:

iptables -A INPUT -i ppp0 -p tcp --dport 563 -j ACCEPT

相关内容