- 系统要求:
- LINUX 内核版本:2.6.9-42 ELsmp 或 2.6.9-55 ELsmp
- 其它内核版本需要重新编译内核,比较麻烦,但是也是可以实现的
- iptables 版本:1.3.7
- LINUX 内核版本:2.6.9-42 ELsmp 或 2.6.9-55 ELsmp
- 安装 iptables 1.3.7[url]http://www.netfilter.org/projects/iptables/files/iptables[/url]
和跟系统内核版本对应的内核模块 kernel-smp-modules-connlimit([url]ftp://ftp.pslib.cz/pub/users/Milan.Kerslager/RHEL-4/stable/[/url])1.3.7.tar.bz2) 配置相应的 iptables 规则,示例如下:
控制单个 IP 的最大并发连接数
1
2
3iptables -I INPUT -p tcp --dport 80 -m connlimit \
--connlimit-above 50 -j REJECT
# 允许单个 IP 的最大连接数为 30控制单个 IP 在一定的时间(比如60秒)内允许新建立的连接数
1
2
3
4
5
6iptables -A INPUT -p tcp --dport 80 -m recent \
--name BAD_HTTP_ACCESS --update --seconds 60 \
--hitcount 30 -j REJECT
iptables -A INPUT -p tcp --dport 80 -m recent \
--name BAD_HTTP_ACCESS --set -j ACCEPT
# 单个 IP 在 60 秒内只允许最多新建 30 个连接
验证:
- 工具: flood_connect.c (用来模拟攻击)
- 查看效果:
1
2
3
4
5
6
7
8
9使用 watch 'netstat -an | grep :21 | \
grep <模拟攻击客户机的 IP> | wc -l'
实时查看模拟攻击客户机建立起来的连接数,
使用 watch 'iptables -L -n -v | \
grep <模拟攻击客户机的 IP>' 查看模拟攻击
客户机被 DROP 的数据包数
```
注意:为了增强iptables防止 CC 攻击的能力,最好调整一下 ipt_recent
的参数:
cat /etc/modprobe.conf
options ipt_recent ip_list_tot=1000 ip_pkt_list_tot=60
记录1000个IP地址,每个地址记录60个数据包
modprobe ipt_recent`
