我想限制一个端口上所有传入的NEW连接的数量,而不仅仅是来自一个IP,如下所示:
iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m limit --limit 3/s -j DROP
但我不明白什么是错的。 它工作了一次/两次,尝试了不同的限制,然后现在放弃了所有新的连接。 (是的,我在每次添加规则之前刷新了iptables)。
编辑1:我试过了
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 5 --hitcount 5 --name SSH -j DROP
它似乎工作。 这会影响所有的连接或只有来自同一个IP的连接?
如果要将新连接的数量限制为3/s
,则必须将规则目标更改为ACCEPT
而不是DROP
:
iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m limit --limit 3/s -j ACCEPT
你可以阅读man iptables
:
limit This module matches at a limited rate using a token bucket filter. A rule using this extension will match until this limit is reached
所以,你的规则将放弃所有新的连接,直到达到极限!