DDoS-Deflate是一款非常小巧的防御和减轻DDoS***的工具,它可以通过监测netstat来跟踪来创建大量互联网连接的IP地址信息,通过APF或IPTABLES禁止或阻档这些非常IP地址。
我们可以使用netstat命令查看当前系统连接的状态,是否有受到DDOS***
[root@localhost ddos]# netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n1 192.168.6.41 Address1 servers)———
安装DDoS-Deflate[root@localhost ~]# wget http://www.inetbase.com/scripts/ddos/install.sh[root@localhost ~]# chmod +x install.sh //添加可执行权限[root@localhost ~]# ./install.sh //执行安装Installing DOS-Deflate 0.6Downloading source files….
…..doneCreating cron to run script every minute…..(Default setting)…..doneInstallation has completed.Config file is at /usr/local/ddos/ddos.confPlease send in your comments and/or suggestions to zaf@vsnl.comDOS-Deflate已经安装好了。DOS-Deflate卸载wget http://www.inetbase.com/scripts/ddos/uninstall.ddoschmod 0700 uninstall.ddos./uninstall.ddosDOS-Deflate安装好之后,全部的文件是放在/usr/local/ddos文件夹中。
[root@localhost ~]#cd /usr/local/ddos/[root@localhost ~]#ls文件说明:ddos.conf –// DDoS-Deflate的配置文件,其中配置防止ddos时的各种行为ddos.sh — // DDoS-Deflate 的主程序,使用shell编写的,整个程序的功能模块ignore.ip.list — // 白名单,该文件中的ip超过设定的连接数时,也不被 DDoS-Deflate 阻止LICENSE –// DDoS-Deflate 程序的发布协议配置ddos.conf
[root@localhost ddos]# cat ddos.conf##### Paths of the script and other files #配置文件也是个shell脚本PROGDIR=”/usr/local/ddos”PROG=”/usr/local/ddos/ddos.sh”IGNORE_IP_LIST=”/usr/local/ddos/ignore.ip.list” #存放白名单的文件CRON=”/etc/cron.d/ddos.cron” #计划任务,默认是每分钟执行一次ddos.shAPF=”/etc/apf/apf”IPT=”/sbin/iptables”##### frequency in minutes for running the script##### Caution: Every time this setting is changed, run the script with –cron##### option so that the new frequency takes effectFREQ=1 #DDoS-Deflate通过linux的计划任务执行,默认为每分钟一次##### How many connections define a bad IP? Indicate that below.NO_OF_CONNECTIONS=150 #定义单个IP达到多少连接时规定为这是一次ddos***##### APF_BAN=1 (Make sure your APF version is atleast 0.96)##### APF_BAN=0 (Uses iptables for banning ips instead of APF)APF_BAN=0 #这里为 “0”,表示使用iptables,而不是APF##### KILL=0 (Bad IPs are’nt banned, good for interactive execution of script)##### KILL=1 (Recommended setting)KILL=1 #是否阻止被定义为ddos***的ip,“1”为阻止##### An email is sent to the following address when an IP is banned.##### Blank would suppress sending of mailsEMAIL_TO=”xxxxx@qq.com” #事件通知人的邮件地址##### Number of seconds the banned ip should remain in blacklist.BAN_PERIOD=600 #阻止被定义为ddos***者ip与本机通信时间,默认为600秒ddos.sh文件内容:[root@localhost ddos]# ./ddos.sh -hDDoS-Deflate version 0.6Copyright (C) 2005, Zaf Usage: ddos.sh [OPTIONS] [N]N : number of tcp/udp connections (default 150)OPTIONS:-h | –help: Show this help screen-c | –cron: Create cron job to run this script regularly (default 1 mins)-k | –kill: Block the offending ip making more than N connections测试防ddos***效果NO_OF_CONNECTIONS=3#这里为了方便测试,设置为3。生产环境下,几十到几百都可以理解为正常,上千肯定就是不正常了,除非是应用内部各个服务器之间的通信通过一台固定ip的机器ssh连接该服务器,当连接到超过3甚至更多时,不会立刻显示连不上,因为ddos.sh默认一分钟运行一次,当过不到一分钟时,会发现连接掉了,查看部署了防ddos软件的服务器上可以看到iptables的策略中多了:DROP all — 31.210.16.29.broad.cs.gd.dynamic.163data.com.cn anywhere说明确实生效了,当10分钟后,iptables上这条策略会被取消的关于如何查看单个IP的连接数目可以通过如下命令查看,依次排列:netstat -na|grep ESTABLISHED|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r -n…………..40 127.0.0.11 121.9.252.281 173.117.140.69ddos***很常见,***效果也很好,比如像前段时间由于维基创始人引发的那次大范围的***。如果有专门防止ddos的硬件设备的话最好,没有的话就利用DDoS-Deflate结合iptables在一定程度上防范ddos***也是一种很好的策略。@vsnl.com>