iptables 添加模块HOWTO(1)


为自己的iptables文档添加一个模块:HOWTO 我在这里为大家介绍下这个模块。

这个文档很简单,只有“准备工作”和“安装步骤”两部分,在这里我要特别感谢ChinaUnix的“gouya”和“lyxmoo”,

他们给了我很大帮助,也谢谢在此期间关心帮助过我的朋友们。

一、准备工作

需要一个内核源码,下载最新内核源码包或者使用系统自带的RPM包均可

需要一个最新的patch-o-matic-ng,可以到官方网站下载最新的快照

http://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/

需要一个最新的iptables,可以到官方网站获取

http://www.netfilter.org/downloads.html

安装步骤(以CentOS-3.4为例)

1、展开压缩包

cd /usr/src

yum install kernel-source

wget http://www.netfilter.org/files/iptables-1.3.1.tar.bz2

wget http://ftp.iasi.roedu.net/netfilter/patch-o-matic-ng/snapshot/patch-o-matic-ng-20050307.tar.bz2

tar xjvf iptables-1.3.1.tar.bz2

tar xjvf patch-o-matic-ng-20050307.tar.bz2

2、给netfilter打补丁

cd /usr/src/linux-2.4

make mrproper

make menuconfig,什么都不做,直接保存退出(见注解1)

uname -r,可得到“2.4.21-27.0.2.EL”的信息

vi Makefile,将“EXTRAVERSION = -27.0.2.ELcustom”改为“EXTRAVERSION = -27.0.2.EL”

cd /usr/src/patch-o-matic-ng-20050307

KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.1 ./runme base(见注解2)

如何给iptables添加模块(v2.2)

2 / 4

一路“y、回车”,如果发现和内核源码有冲突或者其他原因打不上,可以“n、回车”,直到结束

cd /usr/src/linux-2.4

make menuconfig,确认[*] Prompt for development and/or incomplete code/drivers要选中

然后进入Networking options

再进入IP:Netfilter Configuration,会看到增加很多模块,把你想要的选中“”(见注解3)

保存、退出,至此,给netfilter打补丁工作完成

3、编译、并启用netfilter模块

cd /usr/src/linux-2.4

head -n4 Makefile(见注解4)

make dep

make modules SUBDIRS=net/ipv4/netfilter

cp -f net/ipv4/netfilter/*.o /lib/modules/2.4.21-27.0.2.EL/kernel/net/ipv4/netfilter/

depmod –a

4、编译安装iptables

cd /usr/src/iptables-1.3.1

export KERNEL_DIR=/usr/src/linux-2.4

export IPTABLES_DIR=/usr/src/iptables-1.3.1

make BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install

ln -s /lib/iptables /usr/local/lib/iptables(可不做,由于之前的iptables-1.3.0有BUG,所以有可能要用到)

5、测试是否成功

iptables -A FORWARD -m iprange --src-range 192.168.1.5-192.168.1.124 -j ACCEPT

iptables -A OUTPUT -m time --timestart 8:00 --timestop 18:00 -j ACCEPT

iptables -A FORWARD -m string --string "sex" -j DROP

iptables -A FORWARD -m ipp2p --edk --bit -j DROP

[root@platinum root]# iptables -nL

Chain FORWARD (policy ACCEPT)

target prot opt source destination

如何给iptables添加模块(v2.2)

3 / 4

ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 source IP range 192.168.1.5-192.168.1.124

DROP all -- 0.0.0.0/0 0.0.0.0/0 STRING match "sex"

DROP all -- 0.0.0.0/0 0.0.0.0/0 ipp2p v0.7.2 --edk --bit

Chain INPUT (policy ACCEPT)

target prot opt source destination

Chain OUTPUT (policy ACCEPT)

target prot opt source destination

ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 TIME from 8:0 to 18:0 on all days

[root@platinum root]#


相关内容