Search code examples
linuxiptables

iptables limit for every ip address


iptables -A OUTPUT -s xxx.xxx.xxx.xxx -p tcp --sport 1234 -m limit 50/s -j ACCEPT
iptables -A OUTPUT -s xxx.xxx.xxx.xxx -p tcp --sport 1234 -j DROP

I think if I use the config above, it will limit xxx.xxx.xxx.xxx:1234 with 50p/s, but my target is to limit 50p/s for every ip xxx.xxx.xxx.xxx:1234 send to.

Can iptables do such a thing?


Solution

  • Not sure... Try: don't specify the -s option. Put a -i with the interface name receiving the traffic and it will apply for all ips. And if you remove the -i, it will apply more globally for all interfaces.

    Anyway, the limit 50/s means Maximum average matching rate in seconds. If you put --limit-burst 1 for example, it means Maximum initial number of packets to match

    Read this: https://www.cyberciti.biz/faq/iptables-connection-limits-howto/