J
J
jidckii2015-01-13 13:38:11
linux
jidckii, 2015-01-13 13:38:11

How to limit the number of connections per port in linux?

Hello.
Actually a subject.
There is a service, it spins on a specific port, for example 80.
Is there a way, for example, using iptables, to limit the number of connections to it.
Those. if 6 sessions are now installed (it doesn’t matter from the 1st ip or from the 6th), then the 7th is no longer allowed to connect and drop. And as soon as there are 5 of them again, then a new one can be installed again.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valentine, 2015-01-13
@jidckii

iptables -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 10 -j DROP

If this does not work for UDP, you will have to do it directly through the conntrack module

A
Armenian Radio, 2015-01-13
@gbg

It will be easier to do this using the service.
For a TCP service, you can look for a solution with IPTABLES or using xinetd. The second is even easier:

service test
{
    instances = 10 # ограничение в 10 штук
    sock_type =     stream
    protocol =      tcp
    wait =          no
    user =          root
    server =        /home/me/bin/testsmpp        
    redirect =      127.0.0.1 8000
}

For UDP - it is unlikely that something will work out, that's how UDP works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question