DDoS deflate–简单解决VPS被DDOS/CC攻击
為什么80%的碼農都做不了架構師?>>> ??
我想現在大家接觸VPS久了,也知道互聯網上被DDOS,CC是家常便飯,在沒有硬防的情況下,尋找軟件代替是最直接的方法,比如用iptables,但是iptables不能在自動屏蔽,只能手動屏蔽,今天我給大家介紹的就是一款可以自動屏蔽DDOS,CC,SYN攻擊的軟件:DDoS Deflate。
DDoS deflate官方地址:http://deflate.medialayer.com/
DOS DEFLATE是一個輕量級的bash shell腳本,以協助用戶阻止DDOS攻擊,它利用下面的命令創建一個連接到服務器的IP地址列表,以及與他們連接總數。它是在軟件層面上的簡單和最容易安裝的解決方案之一。
如何查看是否被攻擊
在VPS中輸入上面的命令查看
?
| 1 | netstat -ntu |? awk '{print $5}' |? cut -d: -f1 |? sort |? uniq -c |? sort -n |
下面是安裝教程
?
| 1 2 3 | wget http://www.inetbase.com/scripts/ddos/install.sh ? chmod 0700? install.sh ./install.sh |
安裝完以后,你會看到一大篇協議,按q退出即可 :
安裝后文件說明 安裝目錄為:/usr/local/ddos/
ddos.conf ? DDoS-Deflate 的配置文件,其中配置防止ddos時的各種行為
ddos.sh ? DDoS-Deflate 的主程序,使用shell編寫的,整個程序的功能模塊
ignore.ip.list ? 白名單,該文件中的ip超過設定的連接數時,也不被 DDoS-Deflate 阻止
LICENSE ? DDoS-Deflate 程序的發布協議
下面是配置文件的中文說明 大家可以根據配置文件進行修改,默認也可以
?
| 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 | ##### 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 ##### How many connections define a bad IP? Indicate that below. # 單IP發起連接數閥值,不建議設置太低. NO_OF_CONNECTIONS=150 ##### APF_BAN=1 (Make sure your APF version is atleast 0.96) ##### APF_BAN=0 (Uses iptables for banning ips instead of APF) #一般情況下你是使用iptables來做防火墻,所以這里你需要將 APF_BAN的值改為0. APF_BAN=1 ##### 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. # 當單IP發起的連接數超過閥值后,將發郵件給指定的收件人. ##### Blank would suppress sending of mails EMAIL_TO=”root”? // 這里是郵箱,可以替換成你的郵箱 ##### Number of seconds the banned ip should remain in blacklist. # 設置被擋IP多少秒后移出黑名單. BAN_PERIOD=600 |
查看/usr/local/ddos/ddos.sh文件的第117行
?
| 1 | netstat -ntu |? awk '{print $5}' |? cut -d: -f1 |? sort |? uniq -c |? sort -nr > $BAD_IP_LIST |
修改為以下代碼即可!
?
| 1 | netstat -ntu |? awk '{print $5}' |? cut -d: -f1 |? sed -n? '/[0-9]/p' |? sort |? uniq -c |? sort -nr > $BAD_IP_LIST |
卸載
?
| 1 2 3 | wget http: //www .inetbase.com /scripts/ddos/uninstall .ddos chmod 0700 uninstall.ddos . /uninstall .ddos |
白名單設置
有時候默認的白名單經常有失誤,為了避免這個情況,我們可以手工設置白名單的ip,然后強制不允許修改
?
| 1 2 3 | vi /usr/local/ddos/ignore .ip.list? // 手工設置白名單IP chattr +i? /usr/local/ddos/ignore .ip.list ? // 強制不允許修改 chattr -i? /usr/local/ddos/ignore .ip.list ? // 解除不允許修改 |
常見問題
1.如何判斷是否生效
使用web壓力測試,自己攻擊自己
2.重新啟動VPS腳本會自動運行嗎?
會自動運行
3.運行必要軟件是什么
iptables和sendmail 安裝方法 yum install iptables或sendmail sendmail可以不裝。
記得開啟sendmail service sendmail start
4.怎么查看被屏蔽IP
如果屏蔽后,請用iptables -L -n 命令查看被屏蔽的IP
轉載于:https://my.oschina.net/fyzhu/blog/552891
總結
以上是生活随笔為你收集整理的DDoS deflate–简单解决VPS被DDOS/CC攻击的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Go你需要注意的坑在这里!
- 下一篇: Tornado,了解一下