#cp /boot/config-2.6.18-164.el5 /usr/src/linux/.config 复制/boot/config-XX 为 .config为蓝本
# make menuconfig编译内核
在下面选项中启用以下模块
Networking support → Networking Options →Network packet filtering framework →Code Netfilter Configuration
Ü <M> Netfilter connection tracking support
Ü <M> “layer7” match support
Ü <M> “string” match support
Ü <M> “time” match support
Ü <M> “iprange” match support
Ü <M> “connlimit” match support
Ü <M> “state” match support
Ü <M> “conntrack” connection match support
Ü <M> “mac” address match support
Ü <M> "multiport" Multiple port match support
v Networking support → Networking Options →Network packet filtering framework → IP: Netfilter Configuration
Ü <M> IPv4 connection tracking support (required for NAT)
Ü <M> Full NAT
v <M> MASQUERADE target support <M> NETMAP target support <M> REDIRECT target support
为内核添加支持选项(layer7)
#make 开始编译
#make modules_install 安装内核模块 安装在/lib/modules/2.6.28.10/
#make install 安装新内核
编辑grub 把新内核作为默认启动内核 并重启
# cp /etc/rc.d/init.d/iptables ~/iptables
复制/etc/rc.d/init.d/iptables 到~/iptables 为了用service iptables 可用
# cp /etc/sysconfig/iptables.config /root 备份iptables配置文件
# rpm -e iptables-ipv6 iptables iptstate --nodeps
卸载当前系统下的iptables
# tar jxvf iptables-1.4.6.tar.bz2 –C /usr/src
解压iptables 源码包到/usr/src
# cd /usr/src/iptables-1.4.6j
切换到iptables文件夹内
#cp ../netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* ./extensions/ 把layer7中对于iptables的补丁复制到iptables 源码中
./configure --prefix=/usr --with-ksource=/usr/src/linux
配置iptables 默认安装前缀为/usr 内核模块位于 /usr/src/linux下
#make 编译iptables
#make install 安装iptables
# tar zxvf l7-protocols-2009-05-28.tar.gz
安装layer7的
# cd l7-protocols-2009-05-28
切换到目录
# make install
安装layer7规则包
# mv ~/iptables /etc/rc.d/init.d/
把此前备份的 ~/iptables 复制回到/etc/rc.d/init.d/目录下
# cp /root/iptables.config /etc/sysconfig/iptables.config 复制回iptables配置文件
# vim /etc/rc.d/init.d/iptables 编写这个文件
把$iptables的路径改成/usr/sbin/$iptables
利用服务脚本
# service iptables start
启动 iptables 这样iptables就可以即用layer7 模块了
使用layer7
#iptables -t nat -A POSTROUTING -m layer7 --17proto qq -j DROP