一、简介
 iptables layer7的功能可以实现对应用层软件的过滤,例如:限制qq、迅雷等软件,这样对一些公司和学校非常有用。下面介绍具体的实现过程。
二、总体步骤概括
 (1)给内核打补丁,并重新编译内核。
 (2)给iptables源码打补丁,并重新编译iptables
 (3)安装l7proto
三、给内核打补丁并重新编译内核
 (1)下载软件包:linux-2.6.28.10.tar.gz,netfilter-layer7-v2.22.tar.gz.
 (2)给内核打补丁。执行以下命令。

 
  
  1. #tar zxvf linux-2.6.28.10.tar.gz -C /usr/src (一定要解压到/usr/src中)  
  2.   #tar zxvf netfilter-layer7-v2.22.tar.gz -C /usr/src(同上)  
  3.   #cd /usr/src  
  4.   #ln -s linux-2.6.28.10 linux  
  5.   #cd /usr/src/linux/  
  6.   #patch -p1 < ../netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.2.22.pach  
  7.   #cp /boot/config-2.6.18-164.el5 /usr/src/linux/.config  
  8.   #make menuconfig  


   (3)配置内核参数


 (4)开始编译内核

 
  
  1. #make  
  2. #make modules_isntall  
  3. #make install  

   编译安装完内核之,就可以从前系统,进入刚编译好的系统,对iptables打补丁。
四、给iptables打补丁,并重新编译iptables
 (1)

 
  
  1. #cp /etc/init.d/iptables /tmp/iptables  
  2. #cp /etc/sysconfig/iptables-config /tmp  

   这两步的主要功能是为启动iptables而准备,即:可以用service iptables [start|restart|stop]等命令。
 (2)

 
  
  1. #rpm -e iptables-ipv6 iptables ipstate --nodeps (此命令卸载原有的iptables)  
  2. 先下载iptables-1.4.6.tar.bz2,然后将其解压到/usr/src目录中  
  3. #tar jxvf iptables-1.4.6.tar.bz2 -C /usr/src  
  4. #cd /usr/src/iptables-1.4.6  
  5. #cp   
  6.  /usr/src/netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/  
  7.  libxt_layer7.*   ./extensions/  
  8. # ./configure  --prefix=/usr  --with-ksource=/usr/src/linux  
  9. # make  
  10. # make install   

安装完成后启动iptables:

 
  
  1. #mv /tmp/iptables-conifg /etc/sysconfig/  
  2. #mv /tmp/iptables /etc/rc.d/init.d/  
  3. #vim /etc/rc.d/init.d/iptables (在末行模式下输入:%s@/sbin/$IPTABLES@/usr/sbin/$IPTABLES@g)  
  4. #service iptables start 

五、安装 l7-protocls

 
  
  1. # tar zxvf l7-protocols-2009-05-28.tar.gz  
  2. # cd l7-protocols-2009-05-28  
  3. # make install 

六、指定限制QQ规则

 
  
  1. # iptables [specify table & chain] -m layer7 --l7proto [protocol name] -j [action]  
  2. (基本规则)   
  3. # iptables -A FORWARD -m layer7 --l7proto qq -j DROP