Search code examples
ubuntuiptablesnetwork-security

Limit the number of clients on a port using iptables


I realize you can limit the number of tcp connections to a port using iptables. Is there a way to limit the number of unique machines connecting to the port? I do not want to limit a specific ip address, but rather the total number of clients on the port.


Solution

  • I think the question has been already answered here:

    https://serverfault.com/questions/371763/limit-maximum-incoming-connections-to-a-port-using-iptables

    You could use iptables using --connlimit. It makes no sense to repeat the answer here, since you'll find the answer in the link above. I hope that answers your question.

    UPDATE:

    In this case you can use the iplimit module from iptables

    iptables -A INPUT -p tcp --syn -dport 80 -m iplimit --iplimit-above 10 -J REJECT
    

    This will reject connections on port 80 if there are 10 ip addreses connected. 10 ip addresses will translate in 10 unique ip addresses.