Update 20080105
ไม่แน่ใจว่า ถึงตอนนี้ patch-o-matic จะอัพเดต ipp2p ให้ใช้งานได้กับ iptables 1.4.0 หรือยัง แต่คุณ rokoman ได้แนะนำ patch มาให้
http://sources.gentoo.org/viewcvs.py/gentoo-x86/net-firewall/ipp2p/files/ipp2p-0.8.2-iptables-1.4.0.patch?view=markup
รู้สึกว่าจะมาจาก gentoo แต่ผมยังไม่ได้ลองนะครับ
20071228
คำเตือน Segmentation fault <== ไม่สามารถใช้ iptables 1.4.0 กับ ipp2p ได้ ถ้าต้องการใช้ ipp2p ด้วย ควรติดตั้ง iptables 1.3.8 แทน
– ขีดยาวหน่อย มันคือ ขีด 2 ขีดติดกันนะครับ wordpress มันจับมาติดกันเป็นขีดเดียวซะงั้น ถ้าขยัน เดี๋ยวผมจะกลับมาแก้ให้
Netfilter ในเคอร์เนลลีนุกซ์ จะเป็นส่วนจัดการทางด้าน packet filtering โดยมี iptables เป็น user tool ที่ใช้ในการจัดการอีกทีหนึ่ง
ปกติแล้ว netfilter และ iptables นั้นจะทำงานในชั้นที่สูงสุดก็แค่ transport เท่านั้น แต่เนื่องจากแอพลิเคชันบางส่วน เช่น p2p นั้น จำเป็นจะต้องใช้ความสามารถในระดับชั้นที่ 7 หรือ application layer จึงจะสามารถกลั่นกรองได้
L7-filter เป็น patch ที่ช่วยใช้ netfilter และ iptables สามารถกลั่นกรองแพ็คเก็ตในระดับชั้นที่ 7 โดยทั่วๆไปได้ ในขณะที่ ipp2p จะเจาะจงเฉพาะ p2p เท่านั้น
ทั้ง L7-filter และ ipp2p สามารถติดตั้งใช้งานได้หลายแบบ วิธีที่แสดงนี้เป็นแค่วิธีหนึ่งเท่านั้นที่ผมได้ลองติดตั้ง
1. ติดตั้งแพคเกจที่ใช้ในการคอมไพล์และสร้าง kernel image
apt-get update
apt-get install build-essential
apt-get install kernel-package
apt-get install libncurses5-dev
2.
cd /usr/src
wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.12.tar.bz2
tar xvjf linux-2.6.23.12.tar.bz2
ln -s linux-2.6.23.12 linux
wget http://jaist.dl.sourceforge.net/sourceforge/l7-filter/netfilter-layer7-v2.17.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/l7-filter/l7-protocols-2007-11-22.tar.gz
คำเตือน Segmentation fault <== ไม่สามารถใช้ iptables 1.4.0 กับ ipp2p ได้ ถ้าต้องการใช้ ipp2p ด้วย ควรติดตั้ง iptables 1.3.8 แทน
wget http://iptables.org/projects/iptables/files/iptables-1.4.0.tar.bz2
wget ftp://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20071226.tar.bz2
tar xvzf l7-protocols-2007-11-22.tar.gz
tar xvzf netfilter-layer7-v2.17.tar.gz
tar xvjf patch-o-matic-ng-20071226.tar.bz2
tar xvzjf iptables-1.4.0.tar.bz2
ln -s iptables-1.4.0 iptables
3. patch linux kernel & iptables with l7-filter
cd /usr/src/linux
patch -p1 < ../netfilter-layer7-v2.17/kernel-2.6.22-2.6.24-layer7-2.17.patch
cd ../iptables
patch -p1 < ../netfilter-layer7-v2.17/iptables-1.4-for-kernel-2.6.20forward-layer7-2.17.patch
chmod +x extensions/.layer7-test
4. patch linux kernel & iptables with ipp2p (patch-o-matic)
cd ../patch-o-matic-ng-20071226/
./runme –download
Hey! KERNEL_DIR is not set.
Where is your kernel source directory? [/usr/src/linux] <– Enter
Hey! IPTABLES_DIR is not set.
Where is your iptables source code directory? [/usr/src/iptables] <– Enter
./runme ipp2p
Hey! KERNEL_DIR is not set.
Where is your kernel source directory? [/usr/src/linux] <– Enter
Hey! IPTABLES_DIR is not set.
Where is your iptables source code directory? [/usr/src/iptables] <– Enter
Do you want to apply this patch [N/y/t/f/a/r/b/w/q/?] y
5. config and compile kernel
cd /usr/src/linux
cp /boot/config-2.6.22-14-server ./.config
####### make oldconfig
make menuconfig
เลือกไปที่
Networking –> Networking options –> Network packet filtering framework (Netfilter)
–> Core netfilter configuration
เลือก <M> “layer7″ match support
[*] Layer 7 debugging output
ส่วนอันอื่นที่ยังไม่ได้เลือก ก็สามารถเลือกได้ ตามต้องการ
<M> UDP-Lite protocol connection tracking support (EXPERIMENTAL)
<M> SANE protocol support (EXPERIMENTAL)
<M> “TRACE” target support (NEW)
<M> “connlimit” match support (NEW)
<M> “u32″ match support
แล้ว exit ออกมา โดยกด Esc 2 ครั้งติดๆกัน แล้วไปที่ IP: Netfilter Configuration เลือก
<M> IPP2P match support
อยู่ด้านล่างสุดเลย แล้ว exit ออกมา โดยกด Esc 2 ครั้ง ไปเรื่อยๆ จนกระทั่งปรากฏหน้าจอ
Do you wish to save your new kernel configuration?
ให้กด Enter เพื่อบันทึกค่าคอนฟิก
6. คอมไพล์และสร้าง kernel image ใหม่ ขั้นตอนนี้ต้องรอนานหน่อยนะครับ
make-kpkg clean
make-kpkg –initrd –append-to-version=-l7-p2p kernel_image kernel_headers
7. หลังจากรอคอยมานาน ต่อไปก็ติดตั้ง kernel ใหม่
cd /usr/src
dpkg -i linux-image-2.6.23.12-l7-p2p_2.6.23.12-l7-p2p-10.00.Custom_i386.deb
dpkg -i linux-headers-2.6.23.12-l7-p2p_2.6.23.12-l7-p2p-10.00.Custom_i386.deb
reboot
shutdown -r now
8. คอมไพล์และติดตั้ง iptables
cd /usr/src/iptables
make KERNEL_DIR=/usr/src/linux
make install
mv /usr/src/l7-protocols-2007-11-22 /etc/l7-protocols
10. ทดสอบ
iptables -A FORWARD -m layer7 –l7proto bittorrent -j DROP
iptables -A FORWARD -m ipp2p –ipp2p -j DROP
Segmentation fault <== ไม่สามารถใช้ iptables 1.4.0 กับ ipp2p ได้ ซะงั้น (:
11. patch, compile and install iptables 1.3.8 แทน iptables 1.4.0 ที่มีปัญหากับ ipp2p (ไม่ต้อง patch และ compile kernel ใหม่)
cd /usr/src
wget http://iptables.org/projects/iptables/files/iptables-1.3.8.tar.bz2
tar xvjf iptables-1.3.8.tar.bz2
rm iptables
ln -s iptables-1.3.8 iptables
cd iptables
patch -p1 < ../netfilter-layer7-v2.17/iptables-1.3-for-kernel-2.6.20forward-layer7-2.17.patch
chmod +x extensions/.layer7-test
cd ../patch-o-matic-ng-20071226
./runme –download
./runme ipp2p
cd ../iptables
make KERNEL_DIR=/usr/src/linux
make install
12. Test
iptables -A FORWARD -m layer7 –l7proto bittorrent -j DROP
iptables -A FORWARD -m ipp2p –ipp2p -j DROP
(: ขอพักก่อนนะครับ !