我想在iptables中执行每个源IP的速率限制。 例如,将主机可以build立新的SSH连接的速率限制为每分钟5个。 据我所知有两种方法可以做到这一点:
iptables -A INPUT -p tcp --dport 22 -m state --state NEW \ -m hashlimit --hashlimit-name SSH --hashlimit-above 5/min \ --hashlimit-mode srcip -j REJECT iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent \ --rcheck --seconds 60 --hitcount 5 --name SSH --rsource -j REJECT iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW \ -m recent --set --name SSH --rsource -j ACCEPT
我的问题:
Is there any difference in how these two will behave?
不,你写的会在function上做同样的事情。
With an emphasis on performance, which one is preferable?
可以说,最近有更好的performance,因为它维护一个表,但不使用哈希桶。
Is there a significant downside to using both modules?
我不知道你为什么要使用两个。 当你只需要一个模块时,你将会对使用这两个模块的性能产生影响。