添加如下规则:
iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 80 --syn -m recent --name web --rcheck --seconds 30 --hitcount 50 -j LOG --log-prefix 'DDOS:' --log-ip-options
iptables -I RH-Firewall-1-INPUT 2 -p tcp --dport 80 --syn -m recent --name web --rcheck --seconds 30 --hitcount 50 -j DROP
iptables -I RH-Firewall-1-INPUT 3 -p tcp --dport 80 --syn -m recent --name web --set -j ACCEPT
可能会遇到
iptables unknown error 2147483648
之类的错误
问题在于ipt_recent模块默认的hitcount是有大小限制的
#modinfo ipt_recent
parm: ip_list_tot:number of IPs to remember per list (uint)
parm: ip_pkt_list_tot:number of packets per IP to remember (max. 255) (uint)
parm: ip_list_hash_size:size of hash table used to look up IPs (uint)
parm: ip_list_perms:permissions on /proc/net/ipt_recent/* files (uint)
方法:
修改/etc/modprobe.conf,增加:
options ipt_recent ip_pkt_list_tot=100
#service iptables stop
#modprobe -r ipt_recent
#modprobe ipt_recent
#service iptables start
ps:
如在modprobe -r ipt_recent时提示
WARNING: /etc/modprobe.conf line x: ignoring bad line starting with ´option
多半是/etc/modprobe.conf中的内容增加有问题
man 5 modprobe.conf
可以看到
options modulename option...