linux 防DDos脚本

linux 防DDos脚本

DDOS攻击的确是件很悲剧的事情,对于没有实力购买硬件防火墙的小型企业甚至是个人站长来说,你的确需要一个免费的防DDOS攻击脚本.

Medialayer是美国的一家空间提供商,他们提供了一种免费的防DDOS攻击解决方案,项目首页: (D)DoS-Deflate

安装和配置Linux下防DDOS攻击脚本DDoS deflate非常简单,下面Sino Unix 介绍下DDoS deflate的安装和配置步骤.

1.安装 DDoS deflate .

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

//弹出版权信息后,在SSH下键入 q , 即可退出版权信息.

2.配置 DDoS deflate .

安装成功后会提示Config file is at /usr/local/ddos/ddos.conf,所以你可以在ddos.conf里进行简要配置.

[root@SinoUnix~]# vim /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" //白名单
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
//ddos.sh执行的频率,单位是分钟,搭配crontab来执行.
如果你更改了该设置,请执行 /usr/local/ddos/ddos.sh --cron
----------------------------------------------------------------------------
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150
//当哪个IP的连接数达到150就加入黑名单;查看连接数你可以执行
#netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
----------------------------------------------------------------------------
##### 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
//一般情况下你是使用iptables来做防火墙,所以这里你需要将APF_BAN的值改为0.
----------------------------------------------------------------------------
##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1
//将非法的的IP加入iptables的INPUT链中,DROP之.
----------------------------------------------------------------------------
##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO="root"
//给root发一封邮件
----------------------------------------------------------------------------
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600
//关押黑名单中的IP的时长

3.卸载 DDoS deflate ,如果你不想用.

wget http://www.inetbase.com/scripts/ddos/uninstall.ddos
chmod 0700 uninstall.ddos
./uninstall.ddos

4.安装 DDoS deflate 后用Webbech测试的截图

大家可以观察下时间线,效果还是比较明显的.流量单位是MB/s,转化为Mbps需要 *8

此外还要修改两个地方.

1. 在/usr/local/ddos/ddos.sh的第134行.注释掉这行,前面加'#'号

#echo $CURR_LINE_IP >> $IGNORE_IP_LIST

2. 在同个文件大概117行处,将netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr > $BAD_IP_LIST注释掉然后在下面添加

netstat -ntu | awk '{print $5}' | egrep -o "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" | sort | uniq -c | sort -nr > $BAD_IP_LIST

转载于:https://my.oschina.net/duxuefeng/blog/63720

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值