DDoS-Deflate 的配置很简单明了。
(一)安装DDoS-Deflate
(1)下载安装脚本
- wget http://www.inetbase.com/scripts/ddos/install.sh
(2)安装 DDoS-Deflate
- ./install.sh
Installing DOS-Deflate 0.6
Downloading source files.........done
Creating cron to run script every minute.....(Default setting)
....下面是发布协议....
....
这样 DDoS-Deflate,就安装好了
(1)了解 DDoS-Deflate 软件的文件分布
DDoS-Deflate 安装好之后,默认全部在 /usr/local/ddos/ 目录下
- # pwd
/usr/local/ddos - # ls
ddos.conf ddos.sh ignore.ip.list LICENSE
文件说明:
ddos.conf -- DDoS-Deflate 的配置文件,其中配置防止ddos时的各种行为
ddos.sh -- DDoS-Deflate 的主程序,使用shell编写的,整个程序的功能模块
ignore.ip.list -- 白名单,该文件中的ip超过设定的连接数时,也不被 DDoS-Deflate 阻止
LICENSE -- DDoS-Deflate 程序的发布协议
(2)配置 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.sh
-
APF="/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 effect
- FREQ=1 #DDoS-Deflate通过linux的计划任务执行,默认为每分钟一次
- d IP? Indicate that below.
-
NO_OF_CONNECTIONS=150 #定义单个IP达到多少连接时规定为这是一次ddos攻击
-
- ##### How many connections define a ba
-
-
##### 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 mails
-
EMAIL_TO="xyzblood@163.com" #事件通知人的邮件地址
-
-
##### Number of seconds the banned ip should remain in blacklist.
-
BAN_PERIOD=600 #阻止被定义为ddos攻击者ip与本机通信时间,默认为600秒
(3)使用ddos.sh
- 使用“-h”选项显示该命令的提供的选项和功能简介
- 因为安装的时候默认就执行了: ./ddos --cron 了,所以我们什么也不需要做了
- # ./ddos.sh -h
DDoS-Deflate version 0.6
Copyright (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
- NO_OF_CONNECTIONS=3 #这里为了方便测试,设置为3。生产环境下,几十到几百都可以理解为正常,上千肯定就是不正常了,除非是应用内部各个服务器之间的通信
- DROP all -- 31.210.16.29.broad.cs.gd.dynamic.163data.com.cn anywhere
(5)关于如何查看单个IP的连接数目可以通过如下命令查看,依次排列:
- netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -n
- ..............
1 121.9.252.28
1 173.117.140.69
(三)后记
ddos攻击很常见,攻击效果也很好,比如像前段时间由于维基创始人引发的那次大范围的攻击。
如果有专门防止ddos的硬件设备的话最好,没有的话就利用DDoS-Deflate结合iptables在一定程度上防范ddos攻击也是一种很好的策略。