- 论坛徽章:
- 0
|
本文转自:
http://blog.csdn.net/mcsrainbow/archive/2008/11/28/3400580.aspx
[color="#000000"]
重新编译内核,使iptables支持L7filter,对七层应用进行过滤
[color="#000000"]
[color="#000000"]Iptables对于七层上面的应用过滤本身不支持,需要安装第三方的模块方可支持。
[color="#000000"]L7-filter[color="#000000"]是一个iptables的外挂模块,它可以过滤很多种的L7协议,这样能够封杀如P2P、IM等应用。
[color="#000000"]1.适用编译环境
[color="#000000"]操作系统:RedHat Enterprise Linux AS4 U4 以上 且带有GCC编译工具
[color="#000000"]2.软件下载
[color="#000000"]kernel[color="#000000"]:2.6.25
[color="#0000ff"]http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.tar.bz2
[color="#000000"]iptables[color="#000000"]:
[color="#800080"]http://www.netfilter.org/projects/iptables/files/iptables-1.4.0.tar.bz2
[color="#000000"]l7-filter:
[color="#800080"]http://sourceforge.net/project/showfiles.php?group_id=80085
[color="#000000"]netfilter-layer7-v2.20.tar.gz
l7-protocols-2008-04-23.tar.gz
[color="#000000"]3.[color="#000000"]给内核打L7-filter补丁
[color="#000000"]将以上各软件包都解压到 /usr/src 目录
#cd /usr/src
#tar xzvf netfilter-layer7-v2.20.tar.gz
#tar xjvf linux-2.6.25.tar.bz2
#cd linux-2.6.25
#patch -p1 2.6.25-layer7-2.20.patch
[color="#000000"]
[color="#000000"]4.[color="#000000"]编译内核
#make oldconfig
[color="#000000"]使用make oldconfig可以继承老的kernel的配置,为自己的配置省去很多麻烦。
#make menuconfig
[color="#000000"]make menuconfig[color="#000000"]是文字界面下推荐一种方式,在这里可以选择你需要编译到核心的模块。
[color="#000000"]因为前面make oldconfig已经很多都继承老的配置,所以一般配置不要动。
[color="#000000"]有两项需要注意:
[color="#000000"]第一项:(在我的版本里面默认就是选上的)
[color="#000000"] General setup --->features ---> [color="#000000"] Prompt for development and/or incomplete code/drivers
[color="#000000"]第二项:(选择iptables里面关于L7filter的)
[color="#000000"]Networking ---> Networking options --->
--- Network packet filtering framework (Netfilter)
[ ] Network packet filtering debugging [color="#000000"]
Advanced netfilter configuration> [color="#000000"]
Bridged IP/ARP packets filtering-->
Core Netfilter Configuration --->
IP: Netfilter Configuration --->
Bridge: Netfilter Configuration --->
[color="#000000"]Core Netfilter Configuration --->
[color="#000000"]里面有很多的选项,推荐将其全部选择。
[color="#000000"]IP: Netfilter Configuration --->
IP tables support (required for filtering/masq/NAT)
[color="#000000"]该项必须选择,其它项可根据需要选择,不过同样推荐将其全部选择。
#make
#make modules
#make modules_install
#make install
#vi /boot/grub/grub.conf
[color="#000000"]
default=0
[color="#000000"]
修改默认以新的内核启动。
#cp /usr/src/linux-2.6.25/.config /boot/config-2.6.25
[color="#000000"]将新的内核配置文件复制到/boot目录。
#reboot
[color="#000000"]重启服务器。
#uname –r
[color="#000000"]2.6.25
[color="#000000"]重启完成后确认内核版本是否正确。
[color="#000000"]
[color="#000000"]5.[color="#000000"]给iptables打补丁并升级
#rpm -qa |grep iptables
#rpm -e --nodeps iptables1.x.x
[color="#000000"]卸载系统中的旧版本iptables。
#cd /usr/src
#tar xjvf iptables-1.4.0.tar.bz2
#tar xzvf netfilter-layer7-v2.20.tar.gz
#cd iptables-1.4.0
# patch p1 [color="#000000"]iptables v1.4.0
[color="#000000"]确认iptables版本是否正确。
[color="#000000"]
[color="#000000"]6.[color="#000000"]安装l7-protocol
#cd /usr/src/
#tar xzvf l7-protocols-2008-11-23.tar.gz
#cd l7-protocols-2008-11-23
#make install
[color="#000000"]其实就是把响应的目录copy到[color="#000000"] /etc/l7-protocols/
真正调用的是/etc/l7-protocols/protocols/下面的文件
[color="#000000"]可以打开下面具体的文件,里面是一些L7程序特征码的正则表达式形式
[color="#000000"]这样自己也可以按照这样的样子,写自己的特征码。
[color="#000000"]该特征码软件包一直在不停的更新,其后面的日期就是更新的日期,推荐定期选择最新的包进行更新。
[color="#000000"]
[color="#000000"]7.测试
[color="#000000"]#iptables -I FORWARD -p udp --dport 53 -m string --string "tencent" --algo bm -j DROP
#iptables -I FORWARD -p tcp -m multiport --dport 80,443 -m layer7 --l7proto qq -j DROP
#iptables -I FORWARD -p udp --dport 8000 -j DROP
#iptables -I FORWARD -p tcp -m layer7 --l7proto socks -j DROP
#iptables -I FORWARD -p udp --dport 53 -m string --string "messenger" --algo bm -j DROP
#iptables -I FORWARD -p tcp -m multiport --dport 80,443 -m layer7 --l7proto msnmessenger -j DROP
#iptables -I FORWARD -p udp --dport 1863 -j DROP
#iptables -t mangle -A PREROUTING -m layer7 --l7proto qq -j DROP
#iptables -t mangle -A PREROUTING -m layer7 --l7proto msnmessenger -j DROP
可通过上面的策略表达式测试是否成功禁止掉qq和msn。
[color="#000000"]附注:
[color="#000000"]使用-j MARK 参数与TC搭配:
[color="#800080"]http://cha.homeip.net/blog/archives/2005/07/cbqinit.html
[color="#000000"]lsmod可以查看当前加载的模块
[color="#000000"]modprobe[color="#000000"]可以加载模块
[color="#000000"]与iptables相关的模块在下面两个目录:[color="#000000"]/lib/modules/2.6.25/kernel/net/netfilter/
/lib/modules/2.6.25/kernel/net/ipv4/netfilter/
[color="#000000"]
[color="#000000"]相关网址:
[color="#000000"]下载与说明:
[color="#0000ff"]http://l7-filter.sourceforge.net/HOWTO#Get
[color="#000000"]支持协议:
[color="#800080"]http://l7-filter.sourceforge.net/protocols
[color="#000000"]其它:
[color="#800080"]Application Layer Packet Classifier for Linux
[color="#000000"]
[color="#0000ff"]L7-filter Supported Protocols
[color="#000000"]
[color="#800080"]Netfilter Packet Traversal
[color="#000000"]流程图:
[color="#000000"]
![]()
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93182/showart_2162866.html |
|