我们可以使用 iptables 来在一定程度上实现 黑洞 抗 CC (连接耗尽)***的能力, 详细配置如下:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

1. 系统要求:

   1)LINUX 内核版本:<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />2.6.9-42 ELsmp 或 2.6.9-55 ELsmp

     (其它内核版本需要重新编译内核,比较麻烦,但是也是可以实现的)

   2)iptables 版本:1.3.7

        1.3.7.tar.bz2)

   和跟系统内核版本对应的内核模块 kernel-smp-modules-connlimit([url]ftp://ftp.pslib.cz/pub/users/Milan.Kerslager/RHEL-4/stable/[/url])

3. 配置相应的 iptables 规则,示例如下:

    1) 控制单个 IP 的最大并发连接数

        iptables -I INPUT -p tcp --dport 80 -m connlimit \
           --connlimit-above 50 -j REJECT 
        # 允许单个 IP 的最大连接数为 30

    2)控制单个 IP 在一定的时间(比如60秒)内允许新建立的连接数

        iptables -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 个连接

4. 验证:1)工具: flood_connect.c (用来模拟***)

         2)查看效果:

            使用 watch 'netstat -an | grep :21 | \
                 grep <模拟***客户机的 IP> | wc -l'

实时查看模拟***客户机建立起来的连接数,

            使用 watch 'iptables -L -n -v | \
                 grep <模拟***客户机的 IP>' 查看模拟***
                客 户机被 DROP 的数据包数

5. Good luck !

 

 

注意:为了增强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

 

 

附:flood_connect.c 可以从[url]http://linux.softpedia.com/get/System/Networking/THC-Flood-Connect-10399.shtml[/url]下载,本文只是用它作为测试工具,请读者不要用
它去搞破坏,拜托