系統內容
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
650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131227/225915K32-0.jpg" title="QQ20130930112153.jpg" alt="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 ---> Network Packet filtering framework (Netfilter) ”處主要注意兩個地方:
1) ---> Core Netfilter Configuration
//將“Netfilter connection tracking suport (NEW)”選擇編譯為模組(M),需選取此項才能看到layer7支援的配置。
//將layer7、string、state、time、IPsec、iprange、connlimit,tcp……等編譯成模組。
2) ---> 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
本文出自 “乾坤的部落格” 部落格,轉載請與作者聯絡!