kernel2.6下为iptables添加扩展模块
作者:lovegqin@CU
终于实现在kernel2.6下为iptables 添加扩展模块
声明:特别感谢白金大哥的无私帮助,和CUer的无私帮助。到处找资料,成功了,就贴出来给大家分享一下。
因为AS4与CENTOS4都默认没有安装kernel 源代码,所以要先安装kernel源代码
本文以centOS4.0 iptables1.3.5为实验环境。
/data为存放各种数据源码的目录。
1. 安装 kernel源代码
# rpm --import /usr/share/rhn/RPM-GPG-KEY
# up2date redhat-rpm-config rpm-build
# up2date --get-source kernel
# useradd buildcentos
# rpm -ivh /var/spool/up2date/kernel*.src.rpm
# cd /usr/src/redhat/SPECS
# rpmbuild -bp --target=i686 kernel-2.6.spec
# cp -a /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9 /usr/src
2. 初始化内核
cd /usrs/src/linux-2.6.9
uname –a
vi Makefile 改EXTRAVERSION =-5.0.3.EL
保持跟uname -a 的版本一致
# make mrproper
# make menuconfig 直接退出。(为了生成.config)
3. 为内核打补丁并添加模块
cd /data/patch-o-matic-ng-20050801
KERNEL_DIR=/usr/src/linux-2.6.9 IPTABLES_DIR=/data/iptables-1.3.5 ./runme time
(注:runme 后跟需要添加的模块,不要使用base 或其它的命令,会导致后面iptables 不能编译通过。我编译的模块有:time ipv4options psd mport ipp2p quota。很遗憾的是string 模块不支持kernel-2.6 版本)
# 此处为添加Layer-7模块 L7-filter 补丁以及协议描述文件:
http://sourceforge.net/project/showfiles.php?group_id=80085
cd /data
tar -xzvf l7-protocols-2006-01-22
mv l7-protocols-2006-10-18 /etc/l7-protocols
cd /usr/src/linux-2.6.9
patch –p1</data/netfilter-layer7-v2.6/for_older_kernels/
kernel-2.6.9-2.6.10-layer7-1.2.patch
cd /data/iptables-1.3.5
patch –p1 </data/netfilter-layer7-v2.6/ iptables-layer7-2.6.patch
chmod +x extensions/.layer7-test
# 添加Layer-7模块完成
4. 选中你增加的模块
cd /usr/src/linux-2.6.9 make menuconfig
5. 编译netfilter模块
cd /usr/src/linux-2.6.9
make modules_prepare
make M=net/ipv4/netfilter
编译完成netfilter的模块后拷贝编译完成的模块
cp -f /usr/src/linux/net/ipv4/netfilter/*.ko /lib/modules/2.6.5-1.358/kernel/net/ipv4/netfilter/
chmod +x chmod +x /lib/modules/2.6.9-5.0.3.EL/kernel/net/ipv4/netfilter/*.ko
depmod –a
6. 编译iptables
vi /usr/src/linux-2.6.9/include/linux/config.h把下面的三行注释掉
//#ifndef __KERNEL__
//#error including kernel header in userspace; use the glibc headers instead!
//#endif
cd /data/iptables-1.3.5
export KERNEL_DIR=/usr/src/linux-2.6.9 IPTABLES_DIR=/data/iptables-1.3.5
make BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install
完成安装以后测试一下
# iptables -V
# modprobe ipt_time
# modprobe ipt_ipp2p
# lsmod
OK成功。
参考文章:
http://www.redhat.com.cn/kbase/5109.php
http://bbs.chinaunix.net/viewthread.php?tid=592094
http://sourceforge.net/project/showfiles.php?group_id=80085
http://www.debianfordummies.org/ ... Firewall_com_Layer7
http://bbs.chinaunix.net/viewthr ... &extra=page%3D1
http://fanqiang.chinaunix.net/program/other/2005-10-20/3738.shtml
BTW:白金大哥的domain0.02对只要你使用的kernel和kernel源码是一致的,iptables和源码是一致的,是没有问题的。
http://bbs.chinaunix.net/viewthr ... &extra=page%3D1
[
本帖最后由 lili 于 2006-11-21 22:47 编辑 ]