blob: bd369a69b2b6d6ead543bc0a34f5ce1542c1a982 [file] [log] [blame]
Jan Engelhardt21df4af2007-07-09 16:50:17 +00001Allows you to restrict the number of parallel connections to a server per
2client IP address (or client address block).
3.TP
Jan Engelhardt2cae5332011-01-18 18:04:57 +01004\fB\-\-connlimit\-upto\fP \fIn\fP
5Match if the number of existing connections is below or equal \fIn\fP.
6.TP
7\fB\-\-connlimit\-above\fP \fIn\fP
8Match if the number of existing connections is above \fIn\fP.
Jan Engelhardt21df4af2007-07-09 16:50:17 +00009.TP
Jan Engelhardtfea74bf2009-01-12 04:53:18 +010010\fB\-\-connlimit\-mask\fP \fIprefix_length\fP
Jan Engelhardt21df4af2007-07-09 16:50:17 +000011Group hosts using the prefix length. For IPv4, this must be a number between
Jan Engelhardt8d5e7732011-01-18 17:17:00 +010012(including) 0 and 32. For IPv6, between 0 and 128. If not specified, the
13maximum prefix length for the applicable protocol is used.
Jan Engelhardt5da9e632011-01-19 02:09:39 +010014.TP
15\fB\-\-connlimit\-saddr\fP
16Apply the limit onto the source group.
17.TP
18\fB\-\-connlimit\-daddr\fP
19Apply the limit onto the destination group.
20.PP
Jan Engelhardt21df4af2007-07-09 16:50:17 +000021Examples:
22.TP
23# allow 2 telnet connections per client host
Jan Engelhardtfea74bf2009-01-12 04:53:18 +010024iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-above 2 \-j REJECT
Jan Engelhardt21df4af2007-07-09 16:50:17 +000025.TP
26# you can also match the other way around:
Jan Engelhardt2cae5332011-01-18 18:04:57 +010027iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-upto 2 \-j ACCEPT
Jan Engelhardt21df4af2007-07-09 16:50:17 +000028.TP
29# limit the number of parallel HTTP requests to 16 per class C sized \
Jan Engelhardt5da9e632011-01-19 02:09:39 +010030source network (24 bit netmask)
Jan Engelhardtfea74bf2009-01-12 04:53:18 +010031iptables \-p tcp \-\-syn \-\-dport 80 \-m connlimit \-\-connlimit\-above 16
32\-\-connlimit\-mask 24 \-j REJECT
Jan Engelhardt21df4af2007-07-09 16:50:17 +000033.TP
Jan Engelhardt18c475d2009-06-10 20:18:43 +020034# limit the number of parallel HTTP requests to 16 for the link local network
Jan Engelhardt21df4af2007-07-09 16:50:17 +000035(ipv6)
Jan Engelhardtfea74bf2009-01-12 04:53:18 +010036ip6tables \-p tcp \-\-syn \-\-dport 80 \-s fe80::/64 \-m connlimit \-\-connlimit\-above
3716 \-\-connlimit\-mask 64 \-j REJECT
Jan Engelhardt5da9e632011-01-19 02:09:39 +010038.TP
39# Limit the number of connections to a particular host:
40ip6tables \-p tcp \-\-syn \-\-dport 49152:65535 \-d 2001:db8::1 \-m connlimit
41\-\-connlimit-above 100 \-j REJECT