layer7,一个工作在内核的插件,它可以方便iptables工作,例如,可以在公司里更简便的停掉某些不想让大家登录上的网站,例如qq等

要安装最新版的layer7,得装一下与其匹配的新的内核,这里我们用的是2.6.28.10版本,安装layer7所需软件包:l7-protocols-2009-05-28.tar.gz   netfilter-layer7-v2.22.tar.gz
安装新内核后需要重新编译安装的iptables-1.4.6.tar.bz2
 
以上准备就绪后,我们开始正式安装
先将内核解压到/usr/src中
tar zxvf  linux-2.6.28.10.tar.gz  -C  /usr/src
然后将netfilter-layer7-v2.22.tar.gz也解压到/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到linux中,对内核开始打补丁
patch -p1  <  ../netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patch

layer7的安装与使用_layer7

为了我们配置内核方便,将当前内核的config复制过来
cp /boot/config-2.6.18-164.el5  /usr/src/linux/.config
然后配置内核
make menuconfig

layer7的安装与使用_layer7_02

layer7的安装与使用_layer7_03

layer7的安装与使用_layer7_04

layer7的安装与使用_layer7_05

layer7的安装与使用_layer7_06

在配置内核时,切记要把这几项给勾上
Networking support → Networking Options →Network packet filtering framework →Core 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
 
 
Networking support → Networking Options →Network packet filtering framework → IP: Netfilter Configuration
<M> IPv4 connection tracking support (required for NAT)
<M>   Full NAT
<M>     MASQUERADE target support                                                                                   
<M>     NETMAP target support                                                                               
<M>     REDIRECT target support
选择完成后就可以保存退出了
然后就可以make了,很慢长的一个过程,建议新建一个screen,在其中运行
编译完成后,开始安装模块make modules_install
最后make install
 
 
内核安装完成,重启选中新装内核之后,开始对iptables进行重新安装,在这之前,最好是把/etc/init.d/iptables 和/etc/sysconfig/iptables-config拷贝出来,方便后面配置服务
准备完成后,卸载当前系统iptables
rpm  -e  iptables-ipv6  iptables  iptstate  --nodeps
把新的解压到/usr/src下
tar jxvf iptables-1.4.6.tar.bz2 –C  /usr/src
cd到iptables-1.4.6中
将上一个目录中的/netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.*拷贝到当前目录中的extensions/中
cp ../netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.*   ./extensions/
然后开始编译安装iptables
./configure  --prefix=/usr  --with-ksource=/usr/src/linux
make
make install
 
安装layer7的控制文件
tar zxvf l7-protocols-2009-05-28.tar.gz
cd到l7-protocols-2009-05-28中
在这里面可以看到很多网络服务,像qq,xunlei,pplive等

layer7的安装与使用_layer7_07

直接make install
最后把事先拷贝出来的iptables重新放入/etc/rc.d/init.d/中
mv ~/iptables  /etc/rc.d/init.d/
mv iptables-config /etc/sysconfig
启动服务
service iptables start
 
具体用法:
iptables [specify table & chain] -m layer7 --l7proto [protocol name] -j [action] 

layer7的安装与使用_layer7_08