Allow client only 1 connect per 20 seconds
How would you code this rule in iptables:
If anybody tries to do more than 1 connection to port 8191 within 20 seconds, regardless of the protocol, then DROP it and ignore any further connect attempts on that port from that source for 20 seconds.
Quoted 7 lines · Adem
How would you code this rule in iptables:
If anybody tries to do more than 1 connection to port 8191 within 20 seconds, regardless of the protocol, then DROP it and ignore any further connect attempts on that port from that source for 20 seconds.
The following should work, but it somehow doesn't work in iptables v1.4.1.1:
...
# if anybody from the list WATCHLIST, and in the last 20 sec, tries to do new connect attempts then DROP them! /sbin/iptables -A INPUT --match recent --name WATCHLIST --rcheck --seconds 20 -j DROP
# accept client at port 8191 (all protocols) and register in WATCHLIST # BUG: if "-p XXX" is left out or if instead "-p all" is used then the rule gets eliminated! /sbin/iptables -A INPUT -p all --dport 8191 --match recent --name WATCHLIST --set -j DROP ...
It works only if "-p tcp" is specified.
Isn't that a bug in iptables?
Quoted 14 lines · Adem
Quoted 7 lines · Adem
How would you code this rule in iptables:
If anybody tries to do more than 1 connection to port 8191 within 20 seconds, regardless of the protocol, then DROP it and ignore any further connect attempts on that port from that source for 20 seconds.
The following should work, but it somehow doesn't work in iptables v1.4.1.1:
...# if anybody from the list WATCHLIST, and in the last 20 sec, tries to do new connect attempts then DROP them! /sbin/iptables -A INPUT --match recent --name WATCHLIST --rcheck --seconds 20 -j DROP
Quoted 6 lines
# accept client at port 8191 (all protocols) and register in WATCHLIST # BUG: if "-p XXX" is left out or if instead "-p all" is used then the rule gets eliminated! /sbin/iptables -A INPUT -p all --dport 8191 --match recent --name WATCHLIST --set -j DROP ...It works only if "-p tcp" is specified.
From the man page:
These extensions can be used if ‘--protocol tcp’ is specified. These extensions can be used if ‘--protocol udp’ is specified.
Hence, these extensions cannot be used with '--protocol all'. So, it looks like you will need to double the number of rules you have.
Quoted 1 line
Isn't that a bug in iptables?
Doesn't look like it.
Signature · 9 lines
Matt Zagrabelny - [email protected] - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot
Quoted 2 lines · On Tue, 25 Nov 2008 21:07:13 +0100 "Adem" <[email protected]> wrote:
It works only if "-p tcp" is specified.
Isn't that a bug in iptables?
Port numbers only make sense in some higher-level protocols built on top of IP, such as TCP and UDP. What would the "port number" be of an ICMP packet, or an AH or ESP IPsec header, or any of these other ideas..?
Signature · 4 lines
Paul Evans <[email protected]> Tel: +44 (0) 845 666 7778 Fax: +44 (0) 870 163 4694 http://www.mxtelecom.com
Quoted 6 lines · Adem
How would you code this rule in iptables:
If anybody tries to do more than 1 connection to port 8191 within 20 seconds, regardless of the protocol, then DROP it and ignore any further connect attempts on that port from that source for 20 seconds.
NOTE: this is completely untested:
iptables -A INPUT -p tcp --dport 8191 --match state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 8191 --match state --state NEW --match recent --name THROTTLE --set
iptables -A INPUT -p tcp --dport 8191 --match state --state NEW --match recent --name THROTTLE --update --seconds 20 --hitcount 2 --rttl -j DROP
Same rules for '-p udp'.
Cheers,
Signature · 9 lines
Matt Zagrabelny - [email protected] - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot