网关使用的是Debian,使用的内核linux-2.6.15.4和iptables-1.3.5从2006年到现在已经有近一年了,近来看到layer7和ipp2p都有新的东东出来,加上在此内核上编译IPID一直没有通过,所以决定升级下内核和iptables。最后选定的2.6.18和iptables-1.3.6。这些东东都可以从官方站点下载到。

1、下载、解压
下面假设下载的源代码都放在/usr/src目录下:
cd /usr/src
解压:
tar jxvf linux-2.6.18.tar.bz2
tar jxvf iptables-1.3.6.tar.bz2
tar jxvf patch-o-matic-ng-20071128.tar.bz2
tar zxvf netfilter-layer7-v2.14.tar.gz
tar zxvf l7-protocols-2007-10-10.tar.gz
做个链接,方便后续的工作。
ln -s linux-2.6.18 linux
ln -s iptables-1.3.6 iptables
2、下载新的ng
cd /usr/src/patch-o-matic-ng-20071128
看看sources.list,需要下geoip、condition、IPMARK、ROUTE、connlimit、ipp2p等external patch
#./runme --download
就会下载相关的patch了。在这过程中,你需要指定内核和iptables 源码的目录,由于我在上面做了链接,直接默认的就可以了。

Successfully downloaded external patch geoip
Successfully downloaded external patch condition
Successfully downloaded external patch IPMARK
Successfully downloaded external patch ROUTE
Successfully downloaded external patch connlimit
Successfully downloaded external patch ipp2p
Successfully downloaded external patch time
./patchlets/ipv4options exists and is not external
./patchlets/TARPIT exists and is not external
Successfully downloaded external patch ACCOUNT
Successfully downloaded external patch pknock
Hey! KERNEL_DIR is not set.
Where is your kernel source directory? [/usr/src/linux]
Hey! IPTABLES_DIR is not set.
Where is your iptables source code directory? [/usr/src/iptables]
Loading patchlet definitions......................... done

Excellent! Source trees are ready for compilation.
3、用ng对kernel和iptables打上相关的patch
# pwd
/usr/src/new/patch-o-matic-ng-20071128
打上需要的ng patch,下面是有需要的。
KERNEL_DIR=/usr/src/linux-2.6.18 IPTABLES_DIR=/usr/src/iptables-1.3.6 ./runme connlimit
KERNEL_DIR=/usr/src/linux-2.6.18 IPTABLES_DIR=/usr/src/iptables-1.3.6 ./runme geoip
KERNEL_DIR=/usr/src/linux-2.6.18 IPTABLES_DIR=/usr/src/iptables-1.3.6 ./runme ipp2p
KERNEL_DIR=/usr/src/linux-2.6.18 IPTABLES_DIR=/usr/src/iptables-1.3.6 ./runme time
KERNEL_DIR=/usr/src/linux-2.6.18 IPTABLES_DIR=/usr/src/iptables-1.3.6 ./runme u32
在这过程中,会询问你。由于我是需要这些ng patch的,直接y就答应。

4、给kernel和iptables打l7补丁:
给kernel打上l7
cd /usr/src/linux-2.6.18
patch -p1 < /usr/src/netfilter-layer7-v2.14/for_older_kernels/kernel-2.6.18-2.6.19-layer7-2.9.patch
给kernel打l7
cd /usr/src/iptables-1.3.6
patch -p1 < /usr/src/netfilter-layer7-v2.14/iptables-for-kernel-pre2.6.20-layer7-2.14.patch
chmod +x /usr/src/iptables-1.3.6/extensions/.layer7-test
到此,给内核和iptables打补钉已经告一段落。
5、编译内核和iptables。
5.1 编译内核
cd /usr/src/linux-2.6.18
#make mrproper
#make menuconfig
#选择内核模块:这步你要仔细选你需要的东西,由于我原来所用的内核的配置文件config已经选好,我直接load它
#再在此基础上选我需要的东东。
l7相关就在:
Networking --->[*] Networking support
[*] Networking options ---> [*] Network packet filtering (replaces ipchains) ---> [*] Network packet filtering (replaces
ipchains) ---> IP: Netfilter Configuration ---> [*] Layer 7 match support (EXPERIMENTAL)
connlimit <*> Connections/IP limit match support   
呵呵,我发现,2.6.18跟以前旧的内核还是有些差别的,你要仔细选择你所需要的,一定要仔细,如果这方面不懂选啥,请你找相关的
文档来看。
我也把string iprange这些常用的也都给它选上。

最后是保存发退出。
#make-kpkg clean
#make-kpkg --revision hbdebl7 --append-to-version .20071128 --initrd binary-arch
#设置 revision和append-to-version 有个好处,就是能避免和 Debian 官方内核的名字有冲突。

如果不出意外的话,就会在/usr/src/出现
linux-p_w_picpath-2.6.18.20071128_hbdebl7_i386.deb
linux-headers-2.6.18.20071128_hbdebl7_i386.deb
linux-headers会在需要的时候用得到,比如用m-a。
安装新的内核:
dpkg -i linux-p_w_picpath-2.6.18.20071128_hbdebl7_i386.deb
再修改下/boot/grub/menu.lst,把新编译的内核设为默认的选项。
重启系统,用新的内核引导系统。

5.2升级iptables:
cd /usr/src/iptables-1.3.6
export KERNEL_DIR=/usr/src/linux-2.6.18
export IPTABLES_DIR=/usr/src/iptables-1.3.6 make
make BINDIR=/usr/local/sbin LIBDIR=/usr/local/lib MANDIR=/usr/local/man
make BINDIR=/usr/local/sbin LIBDIR=/usr/local/lib MANDIR=/usr/local/man install
5.3安装layer7-protocols:
cd /usr/src/l7-protocols-2007-10-10
make install
然后你就可以开始测试你在新版本内核的iptables的效果了,注意下新版本iptables的路径(你可以把旧版本的iptables给删除掉)
6、ipp2p升级版本和IDIP:
ShadowStar 对ipp2p模块进行了修改和升级版本:
http://linux.chinaunix.net/bbs/thread-914377-1-1.html
直接下载,比如下载ipp2p-0.99.6-r2.tar.gz到/usr/src/
然后:
cd /usr/src/
#tar zxvf ipp2p-0.99.6-r2.tar.gz
#cd /usr/src/ipp2p-0.99.6-r2
#make
#cp libipt_ipp2p.so /usr/local/lib/iptables/
#cp ipt_ipp2p.ko /lib/modules/2.6.18.20071128/
#depmod -a
#modprobe ipt_ipp2p
然后就可以写相关的iptables脚本进行测试了。。
哈哈,用了ShadowStar加强版本的ipp2p后,发现网络近来好了好多啊。谢谢!
为了对付深圳电信adsl的流氓行为,我为编译这个IPID花了不少时间,一直以为自己编译内核步骤有问题。
原来我是一直用2.6.15-4内核的,都不能编译通过,后来升级到2.6.18内核,一下子就通过了。
#/usr/src/
#tar zxvf iptables-ipid-2.1.tar.tar
#cd iptables-ipid-2.1
#make
#cp libipt_IPID.so /usr/local/lib/iptables/
#cp ipt_IPID.ko /lib/modules/2.6.18.20071128/
#depmod -a

#modprobe ipt_IPID
#modinfo ipt_IPID
filename:       /lib/modules/2.6.18.20071128/ipt_IPID.ko
license:        GPL
description:    IP tables IPID modification module
author:         Ssffzz1 < ssffzz1@126.com>
depends:
vermagic:       2.6.18.20071128 PENTIUMIII REGPARM gcc-4.2
编译IPID要注意的问题在上面的那两个帖子大部分已经提及到了。
我是一是选了2.6.18的内核就可以,二是Makefile文件中的一个ld 命令改成gcc命令。其它的都按正常的情况来编译的。
IPID具体的效果我还没有测试,因为深圳电信已经流氓了。

<PS:由于版本不尽相同和各人爱好,你在选择、编译和安装的时候有些地方会不一样,请自己注意,我是做个记录,方便自己查找,大体步骤就是这样了。iptables相关的脚本请阅读相关的文档~_~ >