爲iptables增加layer7補丁(Linux2.6.25內核)

系統環境
RHEL5 [2.6.18-164.el5]

軟件環境

http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.19.tar.bz2
http://www.netfilter.org/projects/iptables/files/iptables-1.4.2.tar.bz2

http://ie.archive.Ubuntu.com/sourceforge/l/l7/l7-filter/netfilter-layer7-v2.20.tar.gz
http://ie.archive.ubuntu.com/sourceforge/l/l7/l7-filter/l7-protocols-2008-10-04.tar.gz

目標功能


爲iptables增加layer7補丁,實現應用層過濾。


一、重新編譯內核

1、將所需軟件下載並上傳到家目錄

[root@localhost ~]# ll

134025151.jpg


2、合併kernel+layer7補丁

[root@localhost ~]# tar jxvf linux-2.6.25.19.tar.bz2 -C /usr/src/

[root@localhost ~]# tar zxvf netfilter-layer7-v2.20.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/linux-2.6.25.19/

[root@localhost linux-2.6.25.19]#patch -p1 < /usr/src/netfilter-layer7-v2.20/kernel-2.6.25-layer7-2.20.patch


3、配置新內核

[root@localhost linux-2.6.25.19]# cp /boot/config-2.6.18-164.el5 .config //沿用舊的內核

[root@localhost linux-2.6.25.19]# make menuconfig

//配置內核時,在“Networking ---> Networking Options ---&gt; Network Packet filtering framework (Netfilter) ”處主要注意兩個地方:
1) ---&gt; Core Netfilter Configuration
//將“Netfilter connection tracking suport (NEW)”選擇編譯爲模塊(M),需選取此項才能看到layer7支持的配置。
//將layer7、string、state、time、IPsec、iprange、connlimit,tcp……等編譯成模塊。

2) ---&gt; IP: Netfilter Configuration
//將“IPv4 connection tracking support (require for NAT)”編譯成模塊。
//將“Full NAT”下的“MASQUERADE target support”和“REDIRECT target support”編譯成模塊。


4、編譯及安裝模塊、新內核

[root@localhost linux-2.6.25.19]make && make modules_install && make install


5、編譯安裝成後,重啓選擇使用新的內核(2.6.25.19)引導系統


二、重新編譯iptables


1、將原來的iptables備份

[root@localhost ~]# uname -r
2.6.25.19 //查看內核版本

進入/etc/init.d/目錄下

[root@localhost init.d]# cp iptables iptables.bak

[root@localhost init.d]# iptables //查看原來的iptables版本

iptables v1.3.5: no command specified

Try `iptables -h' or 'iptables --help' for more information.


2、卸載現有iptables

[root@localhost init.d]# rpm -e iptables --nodeps

warning: /etc/sysconfig/iptables-config saved as /etc/sysconfig/iptables-config.rpmsave


3、合併iptables+layer7補丁

[root@localhost ~]# tar -jxvf iptables-1.4.2.tar.bz2 -C /usr/src/

[root@localhost ~]# cd /usr/src/netfilter-layer7-v2.20/iptables-1.4.1.1-for-kernel-2.6.20forward/

[root@localhost iptables-1.4.1.1-for-kernel-2.6.20forward]# ll

總計 16

-rw-r--r-- 1 1000 1000 9356 2008-08-22 libxt_layer7.c

-rw-r--r-- 1 1000 1000 648 2008-08-22 libxt_layer7.man

[root@localhost iptables-1.4.1.1-for-kernel-2.6.20forward]# cp * /usr/src/iptables-1.4.2/extensions/


4、編譯安裝

[root@localhost iptables-1.4.1.1-for-kernel-2.6.20forward]# cd /usr/src/iptables-1.4.2/

[root@localhost iptables-1.4.2]# ./configure --prefix=/ --with-ksouce=/usr/src/linux-2.6.25.19/

[root@localhost iptables-1.4.2]# make && make install


5、將原備份iptables還原

[root@localhost iptables-1.4.2]# mv /etc/init.d/iptables.bak /etc/init.d/iptables

[root@localhost iptables-1.4.2]# ll /etc/init.d/iptables

-rwxr-xr-x 1 root root 7460 09-18 17:24 /etc/init.d/iptables


6、啓動iptables

[root@localhost ~]# service iptables save


7、安裝l7-protocols模式包

[root@localhost ~]# tar -zxvf l7-protocols-2008-10-04.tar.gz -C /etc/

[root@localhost ~]# mv /etc/l7-protocols-2008-10-04 /etc/l7-protocols


8、測試

[root@localhost ~]# iptables -t filter -A FORWARD -m layer7 --l7proto qq -j DROP

[root@localhost ~]# iptables -L


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章