โน้ตคำสั่งต่างๆ ที่ใช้ไว้ก่อนกันลืม
===============================================================
Update 20071223
พอดีว่า iptables 1.4.0 ออกมาแล้ว ผมได้ลองติดตั้งโดยวิธีนี้ สามารถติดตั้งได้โดยใช้
kernel 2.6.23.12
iptables 1.4.0 + netfilter-layer7-v2.17
patch-o-matic-ng-20071222 + IPP2P v0.8.1_rc1
Update 20071228
iptables 1.4.0 จะมีปัญหา ไม่สามารถใช้งานได้กับ ipp2p
==============================================================
ในที่นี้ผมลองใช้ทั้ง L7-filter และ ipp2p ใครจะใช้อย่างใดอย่างหนึ่งก็ได้นะครับ
apt-get update
apt-get install build-essential
apt-get install kernel-package
ถ้าต้องการใช้คำสั่ง make menuconfig ติดตั้งตามคสั่งบรรทัดด้านล่าง
####################### apt-get install libncurses5-dev
ใช้คำสั่งบรรทัดด้านล่าง ถ้าต้อง kernel source ของ ubuntu (linux-source-2.6.22.tar.bz2)
###################### apt-get install kernel-source
cd /usr/src
wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.9.tar.bz2
tar xvjf linux-2.6.23.9.tar.bz2
ln -s linux-2.6.23.9 linux
wget http://jaist.dl.sourceforge.net/sourceforge/l7-filter/netfilter-layer7-v2.16.1.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/l7-filter/l7-protocols-2007-11-22.tar.gz
wget http://iptables.org/projects/iptables/files/iptables-1.3.8.tar.bz2
wget ftp://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20071208.tar.bz2
tar xvzf l7-protocols-2007-11-22.tar.gz
tar xvzf netfilter-layer7-v2.16.1.tar.gz
tar xvjf patch-o-matic-ng-20071208.tar.bz2
tar xvzjf iptables-1.3.8.tar.bz2
ln -s iptables-1.3.8 iptables
cd /usr/src/linux
patch -p1 < ../netfilter-layer7-v2.16.1/kernel-2.6.22-2.6.23-layer7-2.16.1.patch
cd ../iptables
patch -p1 < ../netfilter-layer7-v2.16.1/iptables-1.3-for-kernel-2.6.20forward-layer7-2.16.1.patch
chmod +x extensions/.layer7-test
cd ../patch-o-matic-ng-20071208/
./runme –download
./runme ipp2p
cd /usr/src/linux
cp /boot/config-2.6.22-14-server ./.config
make oldconfig
เลือก m หรือ y ในหัวข้อที่เกี่ยวกับ layer 7 และ ipp2p ส่วนอันอื่นก็สามารถจะ enter ผ่านไปได้
คอมไพล์และสร้าง kernel image รอนานหน่อยนะครับ
make-kpkg clean
make-kpkg –initrd –append-to-version=-p2p kernel_image kernel_headers
cd /usr/src/iptables
make KERNEL_DIR=/usr/src/linux
make install
ต่อไปก็ติดตั้ง kernel ใหม่
cd ..
dpkg -i linux-image-2.6.23.9-p2p_2.6.23.9-p2p-10.00.Custom_i386.deb
dpkg -i linux-headers-2.6.23.9-p2p_2.6.23.9-p2p-10.00.Custom_i386.deb
cd /usr/src
tar xvzf l7-protocols-2007-11-22.tar.gz
mv /usr/src/l7-protocols-2007-11-22 /etc/l7-protocols
reboot
ลองทดสอบดู
iptables -m ipp2p –help
iptables -m layer7 –help
iptables -A FORWARD -m layer7 –l7proto bittorrent -j DROP
iptables -A FORWARD -m ipp2p –ipp2p -j DROP
root@myubuntu:/usr/src# iptables -L -n -v
Chain INPUT (policy ACCEPT 2385 packets, 153K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 17040 packets, 4942K bytes)
pkts bytes target prot opt in out source destination
484 36972 DROP all — * * 0.0.0.0/0 0.0.0.0/0 LAYER7 l7proto bittorrent
6 2106 DROP all — * * 0.0.0.0/0 0.0.0.0/0 ipp2p v0.8.1_rc1 –ipp2p
Chain OUTPUT (policy ACCEPT 2527 packets, 308K bytes)
pkts bytes target prot opt in out source destination
root@myubuntu:/usr/src# lsmod
Module Size Used by
ipt_MASQUERADE 4864 1
iptable_nat 8708 1
nf_nat 21036 2 ipt_MASQUERADE,iptable_nat
nf_conntrack_ipv4 19848 3 iptable_nat
xt_layer7 13700 1
nf_conntrack 67144 5 ipt_MASQUERADE,iptable_nat,nf_nat,nf_conntrack_ipv4,xt_layer7
nfnetlink 7192 3 nf_nat,nf_conntrack_ipv4,nf_conntrack
ipt_ipp2p 9600 1
iptable_filter 4224 1
ip_tables 15204 2 iptable_nat,iptable_filter
x_tables 16516 5 ipt_MASQUERADE,iptable_nat,xt_layer7,ipt_ipp2p,ip_tables
Update
ถ้า patch connlimit ด้วยจะคอมไพล์ kernel ไม่ผ่าน ใน kernel 2.6.23.9 ได้รวมไว้ใน kernel แล้ว สามารถเลือกเป็น module (m) ได้เลย แต่ว่าเท่าที่ผมได้ลอง iptables 1.3.8 จะยังไม่ support connlimit แต่ใน 1.4.0 rc1 จะสามารถใช้งานได้ แต่ไม่แน่ใจว่ามันจะมี bug ยังไงบ้างหรือเปล่า เพราะมันยังไม่ stable
root@myubuntu:/usr/src/iptables-1.3.8-ipp2p-L7# iptables -V
iptables v1.3.8
root@myubuntu:/usr/src/iptables-1.3.8-ipp2p-L7# iptables -m connlimit -h
iptables v1.3.8: Couldn’t load match `connlimit’:/usr/local/lib/iptables/libipt_connlimit.so: cannot open shared object file: No such file or directory
Try `iptables -h’ or ‘iptables –help’ for more information.
root@myubuntu:/usr/src/iptables-1.3.8-ipp2p-L7#
root@myubuntu:/usr/src/iptables# iptables -V
iptables v1.4.0rc1
root@myubuntu:/usr/src/iptables# iptables -m connlimit -h
……………………….
connlimit v1.4.0rc1 options:
[!] –connlimit-above n match if the number of existing connections is (not) above n
–connlimit-mask n group hosts using mask
Links
http://l7-filter.sourceforge.net/