·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设问答 >> linux系统防止/减轻DDOS攻击脚本(D)DoS Deflate

linux系统防止/减轻DDOS攻击脚本(D)DoS Deflate

作者:佚名      网站建设问答编辑:admin      更新时间:2022-07-23

互联网如同现实社会一样充满钩心斗角,网站被DDOS也成为站长最头疼的事。在没有硬防的情况下,寻找软件代替是最直接的方法,比如用iptables,但是iptables不能在自动屏蔽,只能手动屏蔽。今天要说的就是一款能够自动屏蔽DDOS攻击者IP的软件:DDoS Deflate。

关于DDOS deflate脚本

DDOS deflate是一个轻量级的脚本,以协助阻止拒绝服务攻击的过程中的bash shell脚本。它使用下面的命令来创建一个连接到服务器的IP地址列表,以及与它们的连接总数 。这是最简单的安装软件的解决方案之一。

# netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n

超过了预先配置的连接数的IP地址自动被服务器防火墙阻止!

脚本特点:

1.可以配置白名单的IP地址,通过配置:/usr/local/ddos/ignore.ip.list

2.简单的配置文件:/usr/local/ddos/ddos.conf

3.IP地址被封时间是预先设定的(默认:600秒后自动解除封锁)

4.通过配置文件,脚本可以定时周期性运行(默认是:1分钟)

5.有IP地址被封锁时,可以为指定的邮箱接收电子邮件警报。

安装:

# wget http://www.inetbase.com/scripts/ddos/install.sh

# chmod 0700 install.sh

# ./install.sh

下面解释一下DDOS deflate脚本主配文件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" //白名单地址列表

CRON="/etc/cron.d/ddos.cron"//crond定时任务脚本

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=0 //1:使用APF,0:使用iptables,推荐使用iptables

##### 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” //发送电子邮件报警的邮箱地址,换成自己使用的邮箱即可

##### Number of seconds the banned ip should remain in blacklist.

BAN_PERIOD=600 //屏蔽IP的时间,根据情况调整

最后开启系统crond服务即可。

如何卸载脚本:

# wget http://www.inetbase.com/scripts/ddos/uninstall.ddos

# chmod 0700 uninstall.ddos

# ./uninstall.ddos

来自:http://www.linuxde.net/2011/09/939.html