---
title: "Centos5.3+iptables+l7-filter+IPP2P的实现！"
author: "fp_moon"
date: "2013-11-12T04:46:28Z"
tags: []
categories: ["编程语言"]
slug: "centos5-3-iptables-l7-filter-ipp2p"
draft: false
lastmod: "2013-11-12T04:46:28Z"
id: 1974087
url: "https://fp-moon.iteye.com/blog/1974087"
---

原文：http://www.opsers.org/base/centos5-3-iptables-l7-filter-ipp2pu002639s-true.html
Centos5.3+iptables+l7-filter+IPP2P的实现！
发表于4年前 ⁄ Linux基础 ⁄ 评论数 12 ⁄ 被围观 11,531 views+
这两天和一位朋友，相互研究了一下在IPTABLES中增加新的模块功能。

在网上查了些资料，都没有成功实现，最后，经过测试与调试，最终实现。

现在就把具体步骤贴出来，与大家分享。

个人建议：在安装最新的软件前，大家最好看一下他们的版本与适合的版本。否则，出了问题也找不到原因！

系统环境：

CentOS 5.3

Kernel 2.6.18-128.el5

iptables 已经卸载（采用源码进行安装）


1.下载所需软件包

kernel 2.6.19.7 
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.7.tar.bz2

iptables 1.3.7 
# wget http://www.netfilter.org/projects/iptables/files/iptables-1.3.7.tar.bz2

L7-filter http://sourceforge.net/project/showfiles.php?group_id=80085 
netfilter-layer7-v2.9.tar.gz

l7-protocols-2007-06-22.tar.gz

以上软件全部下载在用户的家目录，全部解压到/usr/src/

2.配置编译新内核

先给内核打包：(当前目录/usr/src)

# cd linux-2.6.19.7

# patch -p1 < /usr/src/netfilter-layer7-v2.9/kernel-2.6.18-2.6.19-layer7-2.9.patch (给内核打上L7-filter的内核补丁)

接下来，就是编译内核

# make menuconfig

选择好layer 7 (位置如下)

-> Networking x 
x -> Networking support (NET ) x 
x -> Networking options x 
x -> Network packet filtering (replaces ipchains) (NETFILTER ) x 
x -> IP: Netfilter Configuration x 
x -> IP tables support (required for filtering/masq/NAT) (IP_NF_IP x 
x -> Layer 7 match support (EXPERIMENTAL) (IP_NF_MATCH_LAYER7 [= x

# make bzImage

# make modules

# make modules_install

以上这三步，用的时间有点长，在实验的时候，做了好几次，郁闷啊！！！！

# make install

# reboot(选择编译好的内核启动系统，也可以在/etc/grub.conf中进行一下设置，就不用在启动的时候选择了)

# uname -r （查看新的内核）

3.更新升级Iptalbes的Layer7补丁：(当前目录/usr/src)

# cd cd iptables-1.3.7

# patch -p1 < /usr/src/netfilter-layer7-v2.9/iptables-layer7-2.9.patch

# chmod +x extensions/.layer7-test

# make KERNEL_DIR=/usr/src/linux-2.6.19.7

# make install KERNEL_DIR=/usr/src/linux-2.6.19.7

# iptables -V（查看IPTABLES的版本） 
4. 安装Layer7 协议文件：(当前目录/usr/src)

# cd l7-protocols-2007-06-22

# make install

5.使用iptables layer-7 filter：

# iptables -t mangle -I PREROUTING -m layer7 –l7proto edonkey -j DROP (禁止edonkey) 
# iptables -t mangle -I PREROUTING -m layer7 –l7proto bittorrent -j DROP (禁止bt) 
# iptables -t mangle -I PREROUTING -m layer7 –l7proto qq -j DROP (禁止QQ通讯) 
# iptables -t mangle -I PREROUTING -m layer7 –l7proto msnmessenger -j DROP (禁止edonkey)
# iptables -t mangle -I PREROUTING -m layer7 –l7proto xunlei -j DROP (禁止迅雷) 
# iptables -t mangle -I PREROUTING -m layer7 –l7proto kugoo -j DROP (禁止kugoo) 
# iptables -t mangle -I PREROUTING -m layer7 –l7proto yahoo -j DROP (禁止Yahoo! Messenger)

6.增加iptables的ipp2p模块：

下载patch-o-matic-ng-20060701软件

ftp://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/

安装IPTABLES的补丁

cd /usr/src/ patch-o-matic-ng-20060701

# export KERNEL_DIR=/usr/src/linux-2.6.19.7

# export IPTABLES_DIR=/usr/src/iptables-1.3.7

# ./runme ipp2p

编译内核

# cd /usr/src/linux-2.6.19.7 
# make modules SUBDIRS=net/ipv4/netfilter

cp -f /usr/src/linux-2.6.19.7/net/ipv4/netfilter/*.ko /lib/modules/2.6.19.7/kernel/net/ipv4/netfilter

chmod +x /lib/modules/2.6.19.7/kernel/net/ipv4/netfilter/*.ko

安装ipp2p协议

cd ipp2p-0.8.2/

make

cp libipt_ipp2p.so /usr/local/lib/iptables/

cp ipt_ipp2p.ko /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/

chmod +x /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/ipt_ipp2p.ko

depmod -a

进行测试

iptables -A FORWARD -m ipp2p –edk –kazaa –bit -j DROP 
iptables -A FORWARD -p tcp -m ipp2p –ares -j DROP 
iptables -A FORWARD -p udp -m ipp2p –kazaa -j DROP

因为没有测试的条件，所以，具体的就没有进行测试，大家如果有条件的话，就自行在环境中测试！！