centos APF,BFD,DDoS Deflate 安装配置

时间: 2011-09-16 / 分类: linux 技术, 安全专区, 系统运维 / 浏览次数: 457 views / 0个评论 发表评论

一, 下载源码包

1
2
3
wget http://www.rfxn.com/downloads/apf-current.tar.gz
wget http://www.rfxn.com/downloads/bfd-current.tar.gz
wget http://www.inetbase.com/scripts/ddos/install.sh

二, 安装APF

1
2
3
4
5
tar -xvzf apf-current.tar.gz
cd apf-9.7-1
./install.sh
cd ..
rm -rf apf-9.7-1

2.2 APF的配置文件设置 — /etc/apf/conf.apf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*禁用调试模式,不过这个是在你确定配置正确之后才修改的。在调试模式下APF会每5分钟重新刷新配置,避免错误配置造成服务器无法提供服务。*/
DEVEL_MODE="0"
 
# 设置服务器允许被访问的TCP端口 - 以cPanel服务器为例
IG_TCP_CPORTS="20,21,22,53,80"
# 设置服务器允许被访问的UDP端口
IG_UDP_CPORTS="20,53"
 
#开启对外访问控制
EGF="1"  
# 设置服务器允许对外访问的TCP端口
EG_TCP_CPORTS="21,25,80,443,43,2089"
# 设置服务器允许对外访问的UDP端口
EG_UDP_CPORTS="20,21,53"

2.3 开启Dshield,屏蔽互联网上有恶意行为的IP

1
2
# IP列表:feeds.dshield.org/top10-2.txt
DLIST_DSHIELD="1"

2.4 APF命令的常用操作

1
2
3
4
5
6
7
8
apf -s  # 启动APF防火墙
apf -r  # 重启APF防火墙
apf -f  # 刷新APF防火墙配置文件
apf -l  # 列出APF的配置信息,与iptables -nL类似
apf -st # APF信息统计。主要包括白名单,黑名单信息。
apf -a IP地址/IP段(FQDN) "注释"   # 将IP/IP段添加到白名单
apf -d IP地址/IP段(FQDN) "注释"   # 将IP/IP段添加到黑名单
apf -u # 将IP/IP段从白/黑名单中删除

2.5 APF 自定义iptables命令
/etc/apf下有2个配置文件postroute.rules和preroute.rules。把Iptables的POSTROUTE和PREROUTE命令放入对应的配置文件,APF在启动时就会自动调用实现NAT转发。
其他Iptables自定义命令可以直接写入/etc/apf/firewall里面。

2.6、APF的访问列表应用
APF的ACL配置文件为/etc/apf/allow_hosts.rules,/etc/apf/deny_hosts.rules
例:只允许来自192.168.0.2的IP访问服务器的SSH端口,屏蔽其他来访。

1
2
3
4
5
6
# 在/etc/apf/allow_hosts.rules添加如下信息:
tcp:in:d=22:s=192.168.0.2
out:d=22:d=192.168.0.2
# 在/etc/apf/deny_hosts.rules添加如下信息:
tcp:in:d=22:s=0/0
out:d=22:d=0/0

三, 安装BFD

1
2
3
tar –zxvf bfd-current.tar.gz
cd bfd-1.4/
./install.sh

3.2 配置BFD

1
2
3
4
5
6
7
8
9
/*设置事件失败次数,达到此数值后禁止引发此事件的IP地址*/
TRIG="5"
/*允许发送告警邮件,设置邮件地址,设置邮件主题*/
EMAIL_ALERTS="1"
EMAIL_ADDRESS=”root@thisme.biz”
EMAIL_SUBJECT="Brute Force Warning for $HOSTNAME"
也可以设置信任列表
编辑/usr/local/bfd/igonre.hosts
每行一个IP

3.3 启动BFD
#bfd –s
在BFD安装后他已经将一个cron任务添加到/etc/cron.d/bfd下,每3分钟执行一次。

BFD日志产生在/var/log/bfd_log。

3.4.查看被阻止的地址
#bfd –a

四,安装DDoS Deflate
4.1

1
2
3
wget http://www.inetbase.com/scripts/ddos/install.sh   //下载DDoS  deflate
chmod 0700 install.sh    //添加权限
./install.sh             //执行

4.2 配置DDoS deflate

下面是DDoS deflate的默认配置位于/usr/local/ddos/ddos.conf ,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
##### 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   //检查时间间隔,默认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        //使用APF还是iptables。推荐使用iptables,将APF_BAN的值改为0即可。
 
##### 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"   //当IP被屏蔽时给指定邮箱发送邮件,推荐使用,换成自己的邮箱即可
 
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600    //禁用IP时间,默认600秒,可根据情况调整

用户可根据给默认配置文件加上的注释提示内容,修改配置文件。

发表评论

您的昵称 *

您的邮箱 *

您的网站