问题原文
原帖链接 · fadedbee · CC BY-SA 3.0
I have some problem network clients which send data too fast.
I want to slow them down, using iptables, or possibly tc.
I've seen iptables solutions like:
sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -m limit --limit 50/second --limit-burst 50 -j ACCEPT
but I think that the limit applies to everything which matches the rule, rather than per client address.
Is there a way of making this rule limit packets per client address?
已采纳解答
原帖链接 · c4f4t0r · CC BY-SA 3.0
you can solve this problem in a simple way, try to use recent module with iptables, recent keep track of the source address:
iptables -m recent -h
recent match options:
[!] --set Add source address to list, always matches.
[!] --rcheck Match if source address in list.
[!] --update Match if source address in list, also update last-seen time.
[!] --remove Match if source address in list, also removes that address from list.
--seconds seconds For check and update commands above.
Specifies that the match will only occur if source address last seen within
the last 'seconds' seconds.
--reap Purge entries older then 'seconds'.
Can only be used in conjunction with the seconds option.
--hitcount hits For check and update commands above.
Specifies that the match will only occur if source address seen hits times.
May be used in conjunction with the seconds option.
--rttl For check and update commands above.
Specifies that the match will only occur if the source address and the TTL
match between this packet and the one which was set.
Useful if you have problems with people spoofing their source address in order
to DoS you via this module.
--name name Name of the recent list to be used. DEFAULT used if none given.
--rsource Match/Save the source address of each packet in the recent list table (default).
--rdest Match/Save the destination address of each packet in the recent list table.
--mask netmask Netmask that will be applied to this recent list.
example for blocking ssh brute force:
iptables -A INPUT -i eth0 -p tcp --syn --dport 22 -m recent --name ssh --set
iptables -A INPUT -i eth0 -p tcp --syn --dport 22 -m recent --name ssh --rcheck --seconds 30 --hitcount 2 -j DROP
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
