linux ddos防御攻击

回复 收藏
Linux Ddos防御攻击
[root@lxh ~]# netstat -ntu |awk '{print $5}'|grep '[0-9]'|cut -d: -f1 |sort |uniq -c|sort -n   #查看统计ip链接数

安装配置ddos deflate
[root@lxh ~]# cd /usr/local/src
[root@lxh src]# wget http://www.inetbase.com/scripts/ddos/install.sh
[root@lxh src]# chmod 744 install.sh           #增加可执行权限
[root@lxh src]# ./install.sh                             #执行安装,安装完后输入q退出说明
[root@lxh ddos]# cd /usr/local/ddos
[root@lxh 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 程序的发布协议
DDoS deflate的默认配置位于/usr/local/ddos/ddos.conf ,默认如下:

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"

FREQ=1 //检查时间间隔,默认1分钟
NO_OF_CONNECTIONS=150 //最大连接数,超过这个数IP就会被屏蔽,一般默认即可
APF_BAN=1 //使用APF还是iptables。推荐使用iptables,将APF_BAN的值改为0即可。
KILL=1 //是否屏蔽IP,默认即可
EMAIL_TO="root" //当IP被屏蔽时给指定邮箱发送邮件,推荐使用,换成自己的邮箱即可
BAN_PERIOD=600 //禁用IP时间,默认600秒,可根据情况调整
查看/usr/local/ddos/ddos.sh文件的第117行
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr > $BAD_IP_LIST
修改为:
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sed -n ‘/[0-9]/p’ | sort | uniq -c | sort -nr > $BAD_IP_LIST
在crontab中添加没分钟执行ddos.sh脚本
# crontab -e
*/1 * * * * /bin/bash /usr/local/ddos/ddos.sh

测试ddos防御。
测试工具ab,源码安装Apache2一般有安装ab。可用which ab查看是否有安装。
如果没有安装可执行
# yum -y install httpd-tools
[li@lxh1 Desktop]$ ab -n 150 192.168.0.102/
[root@lxh ~]# netstat -ntu |awk '{print $5}' |cut -d: -f1 |grep '[0-9]' |sort |uniq -c |sort -nr
     151 192.168.0.101
      1 23.32.248.91
[root@lxh Desktop]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  192.168.0.101        anywhere
这样就禁止了192.168.0.101的访问。
[root@lxh Desktop]# iptables -F    #清除规则
[root@lxh Desktop]# service iptables save   #保存规则
2016-03-10 23:42 举报
已邀请:
0

balich

赞同来自:

谢谢分享。。。
0

xteplinux

赞同来自:

{:4_91:}
0

boy461205160

赞同来自:

顶你个肺
0

Rohero

赞同来自:

0

IceCry

赞同来自:

感谢分享~~~~
0

pwq18627318744

赞同来自:

学习了,很有用

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: