Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 1 | Allows you to restrict the number of parallel connections to a server per |
| 2 | client IP address (or client address block). |
| 3 | .TP |
Jan Engelhardt | 2cae533 | 2011-01-18 18:04:57 +0100 | [diff] [blame] | 4 | \fB\-\-connlimit\-upto\fP \fIn\fP |
| 5 | Match if the number of existing connections is below or equal \fIn\fP. |
| 6 | .TP |
| 7 | \fB\-\-connlimit\-above\fP \fIn\fP |
| 8 | Match if the number of existing connections is above \fIn\fP. |
Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 9 | .TP |
Jan Engelhardt | fea74bf | 2009-01-12 04:53:18 +0100 | [diff] [blame] | 10 | \fB\-\-connlimit\-mask\fP \fIprefix_length\fP |
Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 11 | Group hosts using the prefix length. For IPv4, this must be a number between |
Jan Engelhardt | 8d5e773 | 2011-01-18 17:17:00 +0100 | [diff] [blame] | 12 | (including) 0 and 32. For IPv6, between 0 and 128. If not specified, the |
| 13 | maximum prefix length for the applicable protocol is used. |
Jan Engelhardt | 5da9e63 | 2011-01-19 02:09:39 +0100 | [diff] [blame] | 14 | .TP |
| 15 | \fB\-\-connlimit\-saddr\fP |
| 16 | Apply the limit onto the source group. |
| 17 | .TP |
| 18 | \fB\-\-connlimit\-daddr\fP |
| 19 | Apply the limit onto the destination group. |
| 20 | .PP |
Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 21 | Examples: |
| 22 | .TP |
| 23 | # allow 2 telnet connections per client host |
Jan Engelhardt | fea74bf | 2009-01-12 04:53:18 +0100 | [diff] [blame] | 24 | iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-above 2 \-j REJECT |
Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 25 | .TP |
| 26 | # you can also match the other way around: |
Jan Engelhardt | 2cae533 | 2011-01-18 18:04:57 +0100 | [diff] [blame] | 27 | iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-upto 2 \-j ACCEPT |
Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 28 | .TP |
| 29 | # limit the number of parallel HTTP requests to 16 per class C sized \ |
Jan Engelhardt | 5da9e63 | 2011-01-19 02:09:39 +0100 | [diff] [blame] | 30 | source network (24 bit netmask) |
Jan Engelhardt | fea74bf | 2009-01-12 04:53:18 +0100 | [diff] [blame] | 31 | iptables \-p tcp \-\-syn \-\-dport 80 \-m connlimit \-\-connlimit\-above 16 |
| 32 | \-\-connlimit\-mask 24 \-j REJECT |
Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 33 | .TP |
Jan Engelhardt | 18c475d | 2009-06-10 20:18:43 +0200 | [diff] [blame] | 34 | # limit the number of parallel HTTP requests to 16 for the link local network |
Jan Engelhardt | 21df4af | 2007-07-09 16:50:17 +0000 | [diff] [blame] | 35 | (ipv6) |
Jan Engelhardt | fea74bf | 2009-01-12 04:53:18 +0100 | [diff] [blame] | 36 | ip6tables \-p tcp \-\-syn \-\-dport 80 \-s fe80::/64 \-m connlimit \-\-connlimit\-above |
| 37 | 16 \-\-connlimit\-mask 64 \-j REJECT |
Jan Engelhardt | 5da9e63 | 2011-01-19 02:09:39 +0100 | [diff] [blame] | 38 | .TP |
| 39 | # Limit the number of connections to a particular host: |
| 40 | ip6tables \-p tcp \-\-syn \-\-dport 49152:65535 \-d 2001:db8::1 \-m connlimit |
| 41 | \-\-connlimit-above 100 \-j REJECT |