Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

系統環境:RHEL5 [ 2.6.18-8.el5xen ]。

需要的軟體包含 linux-2.6.25.19 核心、iptables-1.4.2,以及 netfilter-layer7-v2.20 與 l7-protocols 套件。

目標:為 iptables 增加 layer7 補丁,實現應用層過濾。

一、重新編譯核心

1、合併核心與 layer7 補丁。先解開核心與補丁,進入核心目錄後套用 patch:

shell> tar -jxvf linux-2.6.25.19.tar.bz2 -C /usr/src/

shell> tar -zxvf netfilter-layer7-v2.20.tar.gz -C /usr/src/

shell> cd /usr/src/linux-2.6.25.19/

shell> patch -p1 < /usr/src/netfilter-layer7-v2.20/kernel-2.6.25-layer7-2.20.patch

先查看目前核心版本:

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

把新核心與補丁下載到機器上:

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

解開核心與補丁:

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

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

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

2. 配置核心。先沿用舊設定:cp /boot/config-2.6.18-8.el5 .config。

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

在「Networking → Networking Options → Network Packet filtering framework (Netfilter)」處有兩處重點:其一,於 Code Netfilter Configuration 中把「Netfilter connection tracking support」選為模塊(M),否則看不到 layer7 設定,再把 layer7、string、state、time、IPsec、iprange、connlimit 等按需編為模塊。

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

其二,於 IP: Netfilter Configuration 中,把 IPv4 connection tracking 與 Full NAT 下的 MASQUERADE、REDIRECT target 編為模塊。

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

3、編譯並安裝模塊與新核心:make && make modules_install && make install。完成後重啟並選擇新核心(2.6.25.19)引導。

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

這個過程相當耗時,請耐心等候。

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

二、重新編譯 iptables

1、卸載現有 iptables:rpm -e iptables iptstat --nodeps。

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

2、合併 iptables 與 layer7 補丁。先解開 iptables:

shell> tar jxvf iptables-1.4.2.tar.bz2 -C /usr/src/

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

再把 layer7 相關檔案複製進 extensions 目錄:

shell> cd /usr/src/netfilter-layer7-v2.20/iptables-1.4.1.1-for-kernel-2.6.20forward/

shell> cp libxt_layer7.c libxt_layer7.man /usr/src/iptables-1.4.2/extensions/

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

3、編譯安裝。

shell> cd /usr/src/iptables-1.4.2/

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

4、安裝 l7-protocols 模式包:

shell> tar zxvf l7-protocols-2008-10-04.tar.gz -C /etc/

shell> mv /etc/l7-protocols-2008-10-04 /etc/l7-protocols

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

為 iptables 加上 layer7 補丁(Linux 2.6.25 核心)

三、layer7 規則範例

1、layer7 match:可封鎖 qq、msnmessenger、msn-filetransfer、xunlei、edonkey、bittorrent 等應用。

2、string match:例如攔截 DNS 查詢中的 tencent、verycd,或 HTTP 80 埠中的特定字串。

3、state match:丟棄非 SYN 的新連線,放行 ESTABLISHED、RELATED。

4、connlimit match:限制同一 C 段的連線數。

5、time match:只在上班日 08:00–17:00 放行 80 埠。

本文出自「無痕」部落格,請務必保留此出處 https://hucwuhen.blog.51cto.com/6253667/1268652

Copyright © Linux教程網 All Rights Reserved