iptables之7层过滤(封QQ、MSN、P2P等)
来源:互联网 发布:淘宝网广场舞舞蹈服 编辑:程序博客网 时间:2024/03/29 20:18
简介
L7 filter是基于数据流工作的,建立在Netfilter connstrack功能之上。因为一个数据流或者说一个连接的所有数据都是属于同一个应用的,所以L7 filter没有必要对所以的数据包进行模式匹配,而只匹配一个流的前面几个数据包 (比如10个数据包)。当一个流的前面几个数据包包含了某种应用层协议的特征码时 (比如QQ),则这个数据流被L7 filter识别;当前面几个数据包的内容没有包含某种应用层协议的特征码时,则L7 filter放弃继续做模式匹配,这个数据流也就没有办法被识别,L7 filter所支持的协议如下图所示http://l7-filter.sourceforge.net/protocols。
为了学习iptables以及利用它进行应用层的过滤,所以必须先搭建好学习环境。我原来的测试机器装的是CentOS5的系统,而且只安装了基本的文本界面。在后续的学习中需要用到协议分析工具Wireshark,而该软件的很多功能都需要图形环境才能体现。原本以为在装好操作系统的情况下用安装光盘附加软件是件很容易的事,后来发现还没有这么简单。所以必须安装图形环境。当然可以先安装基本的iptables及7层的包然后再安装图形系统。
安装前的准备
7层过滤首先需要内核支持,现在最新的内核是2.6.33但是L7 filter的支持列表只更新到2.6.30.5而且有部份的功能未经测试,而所有经过测试的版本的内核是2.6.28http://l7-filter.sourceforge.net/kernelcompat(如下图所示),为了保证其稳定所以决定将内核升级为2.6.28。
下载所需的软件包
1
2
3
4
wget http:
//www
.kernel.org
/pub/linux/kernel/v2
.6
/linux-2
.6.28.
tar
.bz2
wget http:
//netfilter
.org
/projects/iptables/files/iptables-1
.4.7.
tar
.bz2
wget http:
//downloads
.sourceforge.net
/project/l7-filter/Protocol
%20definitions
/2009-05-28/l7-protocols-2009-05-28
.
tar
.gz?use_mirror=nchc
wget http:
//downloads
.sourceforge.net
/project/l7-filter/l7-filter
%20kernel%20version
/2
.22
/netfilter-layer7-v2
.22.
tar
.gz?use_mirror=nchc
解压以上文件
1
2
3
4
tar
jxvf linux-2.6.28.
tar
.bz2 -C
/usr/src
tar
jxvf iptables-1.4.7.
tar
.bz2 -C
/usr/src
tar
zxvf l7-protocols-2009-05-28.
tar
.gz -C
/usr/src
tar
zxvf netfilter-layer7-v2.22.
tar
.gz -C
/usr/src
卸载系统自带的iptables
1
rpm -e --nodeps `rpm -qa |
grep
iptables`
安装Layer 7
以上操作完成后就可以开始编译内核加入Layer 7的支持了,需注意的是在编译内核中有些选项的选取上一定要注意,安装的成功与否很大程度上取决于内核编译是否成功,内核编译参数如下表所示。
1
2
3
4
5
6
7
8
9
10
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 --- 必选
给新内核加入Layer 7补丁
1
2
cd
/usr/src/linux-2
.6.28/
patch -p1 <
/usr/src/netfilter-layer7-v2
.22
/kernel-2
.6.25-2.6.28-layer7-2.22.patch
编译内核
1
2
3
4
make
menuconfig
make
make
modules_install
make
install
更改启动项后并重启系统
1
vi
/etc/grup
.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)
/grub/splash
.xpm.gz
hiddenmenu
title CentOS (2.6.28)
root (hd0,0)
kernel
/vmlinuz-2
.6.28 ro root=
/dev/VolGroup00/LogVol00
initrd
/initrd-2
.6.28.img
title CentOS (2.6.18-164.el5)
root (hd0,0)
kernel
/vmlinuz-2
.6.18-164.el5 ro root=
/dev/VolGroup00/LogVol00
initrd
/initrd-2
.6.18-164.el5.img
编译安装iptables并支持Layer 7
1
2
3
4
5
6
7
cd
iptables-1.4.7/
cp
/usr/src/netfilter-layer7-v2
.22
/iptables-1
.4.3forward-
for
-kernel-2.6.20forward/* extensions/
.
/configure
--with-ksource=
/usr/src/linux-2
.6.28/
cp
/usr/src/netfilter-layer7-v2
.22
/iptables-1
.4.3forward-
for
-kernel-2.6.20forward/*.* extensions/
.
/configure
--with-ksource=
/usr/src/linux-2
.6.28
make
make
install
安装Layer 7协议
1
2
cd
l7-protocols-2009-05-28/
make
install
测试
1
2
iptables -V
iptables -m layer7 –help
使用iptables layer-7 filter
1
2
3
4
5
6
7
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
0 0
- iptables之7层过滤(封QQ、MSN、P2P等)
- Centos+iptables+l7-filter 封QQ MSN和P2P
- Centos+iptables+l7-filter 封QQ MSN和P2P
- Centos+iptables+l7-filter 封QQ MSN和P2P
- Centos+iptables+l7-filter 封QQ MSN和P2P
- iptables+l7-filter 封QQ MSN和P2P
- iptables+l7-filter 封QQ MSN和P2P
- centos 5.4+Layer7封qq、msn和p2p下载
- 如何封qq和MSN
- iptables屏蔽QQ与MSN
- iptables屏蔽QQ与MSN
- iptables 应用层过滤
- 激动人心!SNS用P2P痛击MSN、QQ
- iptables防火墙详解及使用layer7阻止qq,酷狗,等P2P软件
- Linux下时时聊天(QQ,MSN等)之解决方案-OpenQ
- iptables—包过滤(网络层)防火墙
- Iptables—包过滤(网络层)防火墙
- Iptables—包过滤(网络层)防火墙
- React创建组件的三种方式及其区别
- js删除当前元素的父级元素
- strcpy和memcpy的区别
- js-小米手机上下滑动
- Remoting和Webservice的区别
- iptables之7层过滤(封QQ、MSN、P2P等)
- 关于PRC框架
- Linux下的USB总线驱动 1
- android stdudio 数据库框架greendao3.2使用
- MySQL数据库备份
- NodeJS学习笔记整理(五)交互式运行环境——REPL
- 解决android中,通过run as将应用安装到模拟器或真机上总是覆盖原有同名应用问题
- ASCII码排序
- OUTOJ 简单的计算式(普通方法+队列法)