4、利用recent抵御DOS攻击
# iptables -I INPUT -p tcp --dport 22 -m connlimit -connlimit-above 3 -j DROP
# iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set -name SSH
记录访问tcp 22端口的新连接,记录名称为SSH--set 记录数据包的来源IP,如果IP已经存在将更新已经存在的条目
iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 300 --hitcount 3 --name SSH -j DROP
# 指SSH记录中的IP,300s内发起超过3次连接则拒绝此IP的连接。
5、做应用层的iptables,限制迅雷,QQ: 注意这里的版本有要求的:
iptables-1.4.3以上
kernel-2.6.20以上
试验步骤: 1)给内核打补丁,并重新编译内核
# tar zxvf linux-2.6.28.10.tar.gz -C /usr/src
# tar zxvf netfilter-layer7-v2.22.tar.gz -C /usr/src
# cd /usr/src
# ln –s linux-2.6.28.10 linux
# cd /usr/src/linux/
# patch -p1 < ../netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patch
# cp /boot/config-2.6.18-164.el5 /usr/src/linux/.config
# make menuconfig 编译选着如下内容:
Networking support → Networking Options →Network packet filtering framework →Core Netfilter Configuration
Netfilter connection tracking support
“layer7” match support
“string” match support
“time” match support
“iprange” match support
“connlimit” match support
“state” match support
“conntrack” connection match support
“mac” address match support
"multiport" Multiple port match support
Networking support → Networking Options →Network packet filtering framework → IP: Netfilter Configuration
IPv4 connection tracking support (required for NAT)
Full NAT
MASQUERADE target support
NETMAP target support
REDIRECT target support
编译安装
# make
# make modules_install
# make install 2)给iptables源码打补丁,并重新编译iptables # cp /etc/init.d/iptables ~/iptables
# cp /etc/sysconfig/iptables-config ~/
# rpm -e iptables-ipv6 iptables iptstate --nodeps
# tar jxvf iptables-1.4.6.tar.bz2 –C /usr/src
# cd /usr/src/iptables-1.4.6
# cp ../netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* ./extensions/
# ./configure --prefix=/usr --with-ksource=/usr/src/linux
# make
# make install 3)安装l7proto
# tar zxvf l7-protocols-2009-05-28.tar.gz
# cd l7-protocols-2009-05-28
# make install
# mv ~/iptables /etc/rc.d/init.d/
这里的iptables文件要做修改的将/sbin/$IPTABLES改成/usr/sbin/$IPTABLISH
# service iptables start
# iptables -A FORWARD -m layer7 --l7proto xunlei -j DROP 限制xunlei
限制的相关信息都在这里 /etc/l7-protocols/protocols/ 可以产考,像qq,pplive等都有的