iptables-路由器配置

iptables-路由器配置

我有一台正在自定义设置的路由器。我想仅允许来自内部网络的 SSH,并放弃其他一切。

这是我目前所拥有的。我试过了,但为了再次连接,我不得不重置路由器,所以我认为我遗漏了一些东西:

iptables -F INPUT
iptables -t filter -A INPUT --match state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A INPUT --destination 127.0.0.1 -i lo -j ACCEPT
iptables -t filter -A INPUT -s 192.168.11.0/24 --protocol tcp  --dport $SSH_PORT -j ACCEPT
iptables -t filter -P INPUT DROP

iptables -F FORWARD
iptables -t filter -A FORWARD -s 192.168.11.0/24 --protocol tcp  -j ACCEPT
iptables -t filter -P FORWARD DROP

iptables -F OUTPUT

这是一个好的起点吗?

答案1

不确定为什么里面有-P。

以下是我的做法:

iptables -F INPUT
iptables -t filter -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A INPUT --destination 127.0.0.1 -i lo -j ACCEPT
iptables -t filter -A INPUT -s 192.168.11.0/24 -m tcp -p tcp --dport $SSH_PORT -j ACCEPT
iptables -t filter -A INPUT -j REJECT --reject-with-icmp-host-prohibited

您不需要使用前向链,但如果这是一个脚本,您仍应先刷新所有链。

如果您愿意,您可以选择在最后一行使用 DROP 而不是 REJECT。

答案2

经过审查并使用这些规则一个多月后,我认为可以相当肯定地说这些规则是有效的。我使用 -P 来设置策略默认值。我更喜欢 DROP 而不是 REJECT,因为它使用的资源更少,并且告诉潜在攻击者的信息更少。

沃尔特

相关内容