防止DDOS策略

1:安装服务

yum install -y net-tools httpd -y 

2:搭建基本环境

systemctl stop firewalld
systemctl start httpd
echo "hello world" >> /var/www/html/index.html
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c 
| sort -n

3:模拟攻击

ab -n 1000 -c http://192.168.128.100/index.html

查看数据

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

在这里插入图片描述

4:安装DDoS deflate

wget http://www.inetbase.com/scripts/ddos/install.sh	#下载安装脚本
chmod a+x install.sh		#添加执行权限
./install.sh			#执行脚本

在这里插入图片描述
出现下面的界面就安装完成了,按q退出
在这里插入图片描述

5:配置文件介绍

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"		#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.
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

##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1

##### 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秒

安装后,不需要手动启动,它创建了crontab计划,每1分钟自动启动

6:查看被禁止的ip名单

iptables -L -n

7:服务操作

手动禁止 ip

iptables -A INPUT -s 192.168.100.202 -j DROP

查看禁止 ip

iptables -nvL

解除禁止 ip

iptables -D INPUT -s 192.168.100.202 -j DROP

7:卸载DDoS deflate服务

wget http://www.inetbase.com/scripts/ddos/uninstall.ddos
chmod a+x uninstall.ddos
./uninstall.ddos

猜你喜欢

转载自blog.csdn.net/weixin_47768822/article/details/110918488