iptables之7层过滤封QQ、MSN、P2P
环境vmware-NAT连接上网。
192.168.2.0 192.168.20.0
clent —–>eth0-[linux]-eth1——-[nat]—-intener
by:key1088
准备
1.内核源码
2.iptables 源码
3.netfilter-L7 filter
4.l7-protocols
安装
1.给内核打补丁.编译内核。我使用的2.6.28的内核。
patch -pl < /root/netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patch
编译内核
make menuconfig
选项
General setup —
Prompt for development and/or incomplete code/drivers
Networking —
Networking options —
Network packet filtering framework (Netfilter) —
Core Netfilter Configuration —
<M> Netfilter connection tracking support
<M> "layer7" match support
Layer 7 debugging output
IP: Netfilter Configuration —
<M>FULL NAT #别忘记这个不然没有nat table
make
make moduls_install
make install
2.安装Layer 7协议
cd l7-protocols-2009-05-28/
make install
3.编译iptables
./configure –with-ksoure=/usr/src/linux-2.6.28/
make
make install
4.检测。重启选择启动那个内核。
iptables -V #你的iptables 版本
iptables -m layer7 –help #看看有layer7选项吗
lsmod|grep layer7 #看看有相应的模块吗
iptables -t nat -L #其他tables能不能用。
iptables -t mangle -L
iptables -L
5.测试
iptables -t nat -A POSTROUTING -s 内网ip -j SNAT –to 外防火墙IP #客户端能正常上网,上QQ
iptables -t mangle -I PREROUTING -m layer –l7proto qq -j DROP #退下QQ,看看能不能使用。
6.相应语法
iptables -t mangle -I PREROUTING -m layer7 –l7proto edonkey -j DROP
iptables -t mangle -I PREROUTING -m layer7 –l7proto bittorrent -j DROP
iptables -t mangle -I PREROUTING -m layer7 –l7proto qq -j DROP
iptables -t mangle -I PREROUTING -m layer7 –l7proto msnmessenger -j DROP
iptables -t mangle -I PREROUTING -m layer7 –l7proto xunlei -j DROP
iptables -t mangle -I PREROUTING -m layer7 –l7proto kugoo -j DROP
iptables -t mangle -I PREROUTING -m layer7 –l7proto yahoo -j DROP
参考地址:
http://lzy821218.blog.51cto.com/209800/307349