Linux里的防火墙(下):iptables的扩展模块——l7-filter的安装与功能实现
来源:互联网 发布:淘宝店招950x120 编辑:程序博客网 时间:2024/05/10 11:39
如果在公司里做网络管理员,老板可能会让你屏蔽掉qq和xunlei,那么如果通过iptables来实现这些功能?
首先,要知道qq和xunlei都是特定的服务,它们在传送数据的时候,必然会由一些特征值在数据中,那么我们的iptables如果想要拦截这些数据,就需要知道它们的数据特征值。而l7-filter就是为了这个目的而存在。(当然,不止qq和xunlei,很多协议它都支持)iptables可以支持很多模块,而l7-filter 是一个iptabels的补丁。但是要想给iptables添加这项扩展功能,就需要给linux系统添加l7模块,也就是说需要重新编译内核。
下面我们就来实现这个过程。虽然过程复杂,但是我们可以给iptables在企业里的过滤田间很多功能。
lf-filter的官方网站:l7-filter-sourceforge.net l7-filter.clearfoundation.com
# sourceforge.net 世界上最大的开源项目网站,有数十万个开源项目。
要实现编译配置l7-filter, 我们需要准备:
Linux 2.6内核(l7并不能很好的支持新内核)
l7-protocols
iptables-1.4.6
netfilter-layer7-v2.22
实现过程:
0)先保存下本机的iptables表,如果有的话
iptables-save > /etc/sysconfig/iptables.bak
恢复的时候使用
iptables-restore < /etc/sysconfig/iptables.bak1)下载inetfilter包,iptables 1.4.6和内核源代码包,(建议使用iptables 1.4.6版本 内核 2.6.28.10)解压缩:
tar xf linux- -C /usr/srctar netfilter-la -C /usr/srctar iptables -C /usr/srccd /usr/src2)给内核打补丁
ln -sv linux- linuxcd linuxpatch -p1 <../netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patchcp /boot/config-2.6.18-164.el5 ./.config #复制你当前主机的内核配置文件,这样编译的时候只要加上l7模块就可以了make menuconfig选如下的项
make && make modules install && make install
2.编译并且安装完成后(需要重启加载新内核),卸载原有版本iptables,安装新版本
# 卸载之前先拷贝配置文件cp /etc/init.d/iptables ~/ipteblescp /etc/sysconfig/iptables-config ~/# 卸载rpm -e iptables-ipv6 iptables iptate --nodepsls /usr/src/iptables-1.4.6/extensions # 里面都是各种iptables的补丁# 编译时指向自己编译的内核./configure --prefix=/usr -with-ksource=/usr/src/linux
3. 安装l7-protocols-2009-05-28.tar.gz
# 你可以下载最新版本 解压到/etc后直接make installtar l7-protocols -C /etccd /etc/l7-protocolsmake install
ls /etc/l7-protocols/protocol#里面是各种协议的特征值我们来看一下qq的特征值 cat qq.pat # Tencent QQ Protocol - Chinese instant messenger protocol - http://www.qq.com# Pattern attributes: good notsofast fast# Protocol groups: chat# Wiki: http://www.protocolinfo.org/wiki/QQ# Copyright (C) 2008 Matthew Strait, Ethan Sommer; See ../LICENSE## Over six million people use QQ in China, according to wsgtrsys.# # This pattern has been tested and is believed to work well.## QQ uses three (two?) methods to connect to server(s?).# one is udp, and another is tcp# udp protocol: the first byte is 02 and last byte is 03# tcp protocol: the second byte is 02 and last byte is 03# tony on protocolinfo.org says that now the *third* byte is 02:# "but when I tested on my PC, I found that when qq2007/qq2008 # use tcp protocol, the third byte instead of the second is always 02.## So the QQ protocol changed again, or I have made a mistake, I wonder # that."# So now the pattern allows any of the first three bytes to be 02. Delete# one of the ".?" to restore to the old behaviour.# pattern written by www.routerclub.com wsgtrsysqq^.?.?\x02.+\x03$
3.复制第一步备份的iptables配置文件到当前新内核的iptables配置文件位置
cp iptables /etc/init.dcp iptables-config /etc/sysconfig/# 修改iptabels里定义的iptables命令路径为/usr/sbin/$IPTABLES,在第21行vim /etc/init.d/iptables
试试效果吧,将qq给禁用掉(假设你的主机在192.168.10.0网段)
iptables -t filter -A FORWARD -s 192.168.10.0/24 -m layer7 --l7-proto qq -j REJECT
是不是不能上qq了呢?
补充:
hash里面保存的有你使用的所有命令,它保存使用过的命令路径缓存,这样下次打已经打过的命令速度就快了,但是它有一个坏处,由于我们已经换了iptables的路径,再打会保错
所以我们使用
hash -r 来清除hash缓存
- Linux里的防火墙(下):iptables的扩展模块——l7-filter的安装与功能实现
- Linux里的防火墙(下):iptables的扩展模块——l7-filter的安装与功能实现
- 用Iptables实现Linux的防火墙功能
- Linux下的防火墙iptables
- iptables linux下的防火墙
- Linux里的防火墙:netfilter简介与Iptables的使用(上)
- Linux里的防火墙(中):使用iptables实现DNAT和SNAT
- Linux下防火墙(iptables)的问题
- Linux下IPTABLES防火墙的设定
- Linux下iptables防火墙的基本应用
- Linux防火墙(Iptables)的开启与关闭
- linux防火墙(iptables)的开启与关闭
- Linux防火墙iptables的启动与关闭
- Linux防火墙(Iptables)的开启与关闭
- Linux防火墙(Iptables)的开启与关闭
- Iptables之layer7 -- l7及利用iptables的recent模块来抵御DOS攻击
- Linux防火墙(iptables)的开启与关闭
- Linux防火墙(iptables)的开启与关闭
- 只有一个实例的类
- How to get a type in C++ when its template argument is the argument
- UML中几种类间关系:继承、实现、依赖、关联、聚合、组合的联系与区别
- 关于二十三种设计模式的另解
- XCODE4+iOS4.3在开发中遇到的苦逼问题汇总。
- Linux里的防火墙(下):iptables的扩展模块——l7-filter的安装与功能实现
- Asp.net MVC学习日记十二(强大的MvcContrib,自动生成html元素)
- 如何编出健壮的代码,java编程30条规则(一)
- Java一览无余:Java精品学习视频教程下载汇总 (随时更新)
- open_flash_chat
- 通过栈来实现队列
- 折半查找
- ural1297后缀树组--2
- 直接获取IP地址的函数