怎樣配置DDoS deflate
下載:ofollow,noindex" target="_blank">http://www.inetbase.com/scripts/ddos/
DDoS deflate 工作原理
每分鐘檢測一次IP連線狀況,當某些IP連線超過配置指令碼限制的連線數,程式會自動禁止這些IP一段時間,以達到防禦攻擊的目的
DDoS deflate官方網站:http://deflate.medialayer.com/
Installation 安裝
wgethttp://www.inetbase.com/scripts/ddos/install.sh
chmod 0700 install.sh
./install.sh
Uninstallation 解除安裝
wgethttp://www.inetbase.com/scripts/ddos/uninstall.ddos
chmod 0700 uninstall.ddos
./uninstall.ddos
檢查是否遭到ddos攻擊命令
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
DDoS deflate的預設配置位於/usr/local/ddos/ddos.conf ,內容如下:
##### Paths of the script and other files
PROGDIR=”/usr/local/ddos”
PROG=”/usr/local/ddos/ddos.sh”
IGNORE_IP_LIST=”/usr/local/ddos/ignore.ip.list”//IP地址白名單
CRON=”/etc/cron.d/ddos.cron”//定時執行程式
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//檢查時間間隔,預設1分鐘
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150//最大連線數,超過這個數IP就會被遮蔽,一般預設即可
##### 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=1//使用APF還是iptables。推薦使用iptables,將APF_BAN的值改為0即可。
##### KILL=0 (Bad IPs are’nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1//是否遮蔽IP,預設即可
##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO=”root”//當IP被遮蔽時給指定郵箱傳送郵件,推薦使用,換成自己的郵箱即可
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600//禁用IP時間,預設600秒,可根據情況調整
試用了一會,感覺還不錯,比我以前用的分析nginx日誌封IP的指令碼要好些,假如幾個虛擬主機使用不同的網站日誌,就必須執行幾個分析日誌的指令碼,
這個指令碼就用一個就可以把整個伺服器保護起來了。但這個也存在一些問題,剛開始的時候把mysql伺服器給封掉了,搞的我手忙腳亂的解封,
然後把mysql伺服器IP新增白名單,誰知過會他過了段時間又把白名單刪除了,又給mysql伺服器封了,不得以解除安裝了一次。
研究了一下程式碼才發現,他禁止的IP也新增到白名單裡,然後解封的時候通過tmp目錄裡的unban.xxxxx檔案將白名單裡禁止的IP再刪除,
這樣這個IP就不再受保護。所以我把mysql伺服器IP新增白名單之後程式根據這個BAN_PERIOD=600 引數在10分鐘後刪除,所以就出現了你恢復他繼續封的怪圈,白名單設定檔案應該和禁止解禁這個IP記錄檔案分開就好了。
使用心得:
安裝後第一時間要將白名單設定好,最好觀察一段時間看是不是正常,以免一些和伺服器需要保持連線的IP被封,比如mysql伺服器,rsync備份伺服器等等,這些機器往往都需要和網站伺服器保持大量連線