##### 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
# 设置检测时间间隔,默认是分钟,由于系统使用crontab功能,最小单位是分钟
FREQ=1
##### How many connections define a bad IP? Indicate that below.
# NO_OF_CONNECTIONS默认是150,这是一个经验值,如果服务器性能比较高,可以设置200以上,以避免误杀
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)
# 使用APF屏蔽IP,如果设置为0就使用iptables,如果使用APF则需要先安装,比如centos中默认就没有安装
APF_BAN=0
##### 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=""
##### Number of seconds the banned ip should remain in blacklist.
# 解锁的时间,单位为秒,可以设置更长时间
BAN_PERIOD=86400
ddos.sh内容:
# 载入配置文件
load_conf()
{
CONF="/usr/local/ddos/ddos.conf"
# $CONF是文件,使用source载入
if [ -f "$CONF" ] && [ ! "$CONF" == "" ]; then
source $CONF
else
head
echo "\$CONF not found."
exit 1
fi
}
# 显示帮助,比如如果要收到干掉当前超过N个连接的IP,使用sh ddos.sh -k 150, sh ddos.sh -h 显示帮助, sh ddos.sh -c创建cron job
showhelp()
{
head
echo 'Usage: ddos.sh [OPTIONS] [N]'
echo 'N : number of tcp/udp connections (default 150)'
echo 'OPTIONS:'
echo '-h | --help: Show this help screen'
echo '-c | --cron: Create cron job to run this script regularly (default 1 mins)'
echo '-k | --kill: Block the offending ip making more than N connections '
}