環境:
- Kernel Source: /usr/src/linux
- Iptables Source: /usr/local/src/iptables-1.3.4
※建議一併安裝 L7-filter, 先參考「L7-filter 安裝實錄」完成所有 patch (但不要安裝), 再進行本篇的安裝步驟
從 patch-o-matic-ng/snapshot 路徑中下載最新的檔案:
cd /usr/local/src/
wget ftp://ftp./pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20060111.tar.bz2
tar -jxf patch-o-matic-ng-20060112.tar.bz2
patch kernel source & iptables source:
cd patch-o-matic-ng-20060112
KERNEL_DIR=/usr/src/linux \
IPTABLES_DIR=/usr/local/src/iptables-1.3.4 \
./runme base
其中, base 是指 patch-o-matic-ng base repository 裡的所有模組, 過程中一一選擇是否安裝; 亦可直接列出想安裝的模組名稱, 如: ./runme connlimit mport time, 只提示 connlimit、mport、time 這三個模組, 過程中只要回答 y 即可
模組名稱與說明可從這個網頁得知: patch-o-matic base repository (更多的模組說明可點選網頁左側 "* repository" )
重新編譯、安裝核心, 在 make oldconfig 或 make menuconfig 時, 把剛剛新增的 netfilter 項目設定為模組 ( m ):
cd /usr/src/linux
make mrproper
make oldconfig
make menuconfig
make
make modules_install
make install
重新編譯、安裝 iptables:
cd /usr/local/src/iptables-1.3.4/
chmod 777 ./extensions/.*
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux
make install-devel
重開機後, 選擇新編譯好的核心版本, iptables 就能使用 Layer-7 (如果先前有 patch 的話) 和自選的 patch-o-matic 模組.
應用實例:
限制 http 連線數目:
iptables -A INPUT -p tcp --dport 80 --syn -m connlimit --connlimit-above 5 -j DROP
上班時間禁用 msn 聊天 (與 L7-filter 配合):
iptables -A FORWARD -m time --timestart 9:00 --timestop 18:00 --days Mon,Tue,Wed,Thu,Fri -m layer7 --l7proto msnmessenger -j DROP
封鎖範圍埠口:
iptables -A FORWARD -p tcp -m mport --ports 5800:6000 -j DROP
查看語法說明:
參考資料:
相關網頁: