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/ 目錄下
1
2
3
4
5
|
#
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#####
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 #####
Number of seconds the banned ip should remain in blacklist. BAN_PERIOD=600
#阻止被定義爲ddos攻擊者ip與本機通信時間,默認爲600秒 |
(3)使用ddos.sh
使用“-h”選項顯示該命令的提供的選項和功能簡介
因爲安裝的時候默認就執行了: ./ddos --cron 了,所以我們什麼也不需要做了
1
2
3
4
5
6
7
8
9
10
|
#
./ddos.sh -h DDoS-Deflate
version 0.6 Copyright
(C) 2005, Zaf <[email protected]> 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 |
(4)測試防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上這條策略會被取消的
(5)關於如何查看單個IP的連接數目可以通過如下命令查看,依次排列:
netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -n
..............
40 127.0.0.1
1 121.9.252.28
1 173.117.140.69
(三)後記
ddos攻擊很常見,攻擊效果也很好,比如像前段時間由於維基創始人引發的那次大範圍的攻擊。
如果有專門防止ddos的硬件設備的話最好,沒有的話就利用DDoS-Deflate結合iptables在一定程度上防範ddos攻擊也是一種很好的策略