SuChart.Blog -> My Online Notebook <-

กุมภาพันธ์ 6, 2008

Kernel-2.6.23 + iptables-1.4.0 + L7-filter-2.17 + ipp2p-0.8.2 on Gentoo

Filed under: Linux, gentoo — suchart @ 3:42 pm

กลัวว่าแฟนๆ ของ gentoo จะน้อยใจ ที่ไม่ได้เขียนถึง ทั้งๆที่แอบไปขโมย patch เขามาใช้ เขียนคร่าวๆ พอเป็นแนวทาง

1.

mygentoo-2 ~ # emerge --sync

mygentoo-2 ~ # nano /etc/portage/package.keywords

net-firewall/iptables ~x86
net-misc/l7-filter ~x86
net-misc/l7-protocols ~x86
net-firewall/ipp2p ~x86

2.

mygentoo-2 ~ # nano /etc/portage/package.use

net-firewall/iptables l7filter

3.

mygentoo-2 ~ # emerge l7-filter

4. คอมไพล์ และติดตั้งเคอร์เนล และรีบูตเข้าสู่เคอร์เนลใหม่ สำหรับที่ผมทำ ประมาณนี้

# mount /boot

# cd /usr/src/linux

# cp .config config.1

# make menuconfig

General setup => (-l7) Local version - append to kernel release

ส่วนอันอื่่นที่เกี่ยวกับ Netfilter ก็ดูได้จากโพสต์อันก่อนๆ นะครับ ง่ายๆ ก็คือผมเลือกทั้งหมดแหละครับ โดยอันไหนเลือกเป็นโมดูลได้ก็เลือกเป็นโมดูลไว้ก่อน

นอกจากนี้ผมยังรวม scsi disk controller driver ของเครื่องเข้าไว้ในเคอร์เนลเลย จึงไม่ต้องใช้ initrd

# make

# make modules_install

# make install

# nano /boot/grub/grub.conf

default 1
timeout 5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title=Gentoo Linux 2.6.23-gentoo-r6
root (hd0,0)
kernel /boot/kernel-genkernel-x86-2.6.23-gentoo-r6 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=/dev/sda3 udev doscsi
initrd /boot/initramfs-genkernel-x86-2.6.23-gentoo-r6

title=Gentoo Linux 2.6.23-r6-l7
root (hd0,0)
kernel /boot/vmlinuz-2.6.23-gentoo-r6-l7 root=/dev/sda3

แล้วรีบูตเข้าสู่เคอร์เนลที่ติดตั้งใหม่

# reboot

5.

mygentoo-2 ~ # emerge iptables

6.

mygentoo-2 ~ # emerge ipp2p

7. Test

mygentoo-2 ~ # iptables -A FORWARD -m ipp2p --ipp2p -j DROP
mygentoo-2 ~ # iptables -A FORWARD -m layer7 --l7proto bittorrent -j DROP
mygentoo-2 ~ # iptables -nvL
Chain INPUT (policy ACCEPT 30 packets, 2232 bytes)
pkts bytes target prot opt in out source destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DROP all — * * 0.0.0.0/0 0.0.0.0/0 ipp2p v0.8.2 –ipp2p
0 0 DROP all — * * 0.0.0.0/0 0.0.0.0/0 LAYER7 l7proto bittorrent

Chain OUTPUT (policy ACCEPT 17 packets, 1844 bytes)
pkts bytes target prot opt in out source destination
mygentoo-2 ~ #

กุมภาพันธ์ 2, 2008

Kernel-2.6.24 + iptables-1.4.0 + L7-filter-2.17 + ipp2p-0.8.2 on Debian 4.0

Filed under: Debian, Linux, Ubuntu — suchart @ 2:20 pm

20080202-1400

Kernel-2.6.24 + iptables-1.4.0 + L7-filter-2.17 + ipp2p-0.8.2 on Debian 4.0

คราวนี้ ผมไม่ใช้ ipp2p-0.8.1_rc1 จาก patch-o-matic แล้ว จะใช้ ipp2p-0.8.2 จาก ipp2p.org แทน บวกกับ patch ที่แอบขโมยมาจาก gentoo :-)

1.

apt-get update
apt-get install build-essential
apt-get install kernel-package
apt-get install libncurses5-dev

2.

cd /usr/src/
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.24.tar.bz2
tar xvjf linux-2.6.24.tar.bz2
ln -s linux-2.6.24 linux

wget http://nchc.dl.sourceforge.net/sourceforge/l7-filter/netfilter-layer7-v2.17.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/l7-filter/l7-protocols-2008-01-16.tar.gz

wget http://iptables.org/projects/iptables/files/iptables-1.4.0.tar.bz2

tar xvzf l7-protocols-2008-01-16.tar.gz
tar xvzf netfilter-layer7-v2.17.tar.gz
tar xvjf 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. config and compile kernel

cd /usr/src/linux
cp /boot/config-2.6.18-5-686 ./.config
make menuconfig

เลือกไปที่

Networking –> Networking options –> Network packet filtering framework (Netfilter) –> Core netfilter configuration
เลือกเพิ่ม
<M> Netfilter connection tracking support
<M> “layer7″ match support
[*] Layer 7 debugging output

ส่วนอันอื่นที่ยังไม่ได้เลือก ก็สามารถเลือกได้ ตามต้องการ สำหรับผม ในการติดตั้งครั้งนี้ จะเลือกทุกอันเลย โดยจะเลือกเป็นโมดูล [M] ไว้ก่อน
แล้ว exit ออกมา โดยกด Esc 2 ครั้งติดๆกัน แล้วไปที่ IP: Netfilter Configuration เลือกเพิ่ม

<M> IPv4 connection tracking support (required for NAT)
<M> Full NAT

อยู่ด้านล่างสุดเลย แล้ว exit ออกมา โดยกด Esc 2 ครั้ง ไปเรื่อยๆ จนกระทั่งปรากฏหน้าจอ

Do you wish to save your new kernel configuration?

ให้กด Enter เพื่อบันทึกค่าคอนฟิก

5. คอมไพล์และสร้าง kernel image ใหม่ ขั้นตอนนี้ต้องรอนานหน่อยนะครับ

make-kpkg clean
make-kpkg --initrd --append-to-version=-l7 kernel_image kernel_headers

6. หลังจากรอคอยมานาน ต่อไปก็ติดตั้ง kernel ใหม่

cd /usr/src
dpkg -i linux-image-2.6.24-l7_2.6.24-l7-10.00.Custom_i386.deb
dpkg -i linux-headers-2.6.24-l7_2.6.24-l7-10.00.Custom_i386.deb

ตรวจสอบไฟล์ /boot/grub/menu.lst ว่าค่า default เป็นเคอร์เนลที่ติดตั้งใหม่

shutdown -r now

8. คอมไพล์และติดตั้ง iptables

cd /usr/src/iptables
make KERNEL_DIR=/usr/src/linux
make install
mv /usr/src/l7-protocols-2008-01-16 /etc/l7-protocols

9. คอมไพล์และติดตั้ง ipp2p

cd /usr/src
wget http://ipp2p.org/downloads/ipp2p-0.8.2.tar.gz
wget http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/net-firewall/ipp2p/files/ipp2p-0.8.2-kernel-2.6.22.patch
wget http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/net-firewall/ipp2p/files/ipp2p-0.8.2-iptables-1.4.0.patch
tar xvzf ipp2p-0.8.2.tar.gz

cp -a ipp2p-0.8.2 ipp2p-0.8.2.orig
cd ipp2p-0.8.2
patch -p1 <../ipp2p-0.8.2-kernel-2.6.22.patch
patch -p1 <../ipp2p-0.8.2-iptables-1.4.0.patch

# ถ้าใช้ ld จะมีปัญหาในการโหลดโมดูล แก้ให้ใช้ gcc ที่บรรทัดท้ายๆของไฟล์ Makefile

vi Makefile

libipt_ipp2p.so: libipt_ipp2p.c ipt_ipp2p.h
$(CC) $(CFLAGS) $(IPTABLES_OPTION) $(IPTABLES_INCLUDE) -fPIC -c libipt_ipp2p.c
@# ld -shared -o libipt_ipp2p.so libipt_ipp2p.o
$(CC) -shared -o libipt_ipp2p.so libipt_ipp2p.o

clean:
-rm -f *.o *.so *.ko .*.cmd *.mod.c
endif

make
cp libipt_ipp2p.so /usr/local/lib/iptables/
cp ipt_ipp2p.ko /lib/modules/2.6.24-l7/kernel/net/netfilter/
depmod -a

11. Test

iptables -A FORWARD -m ipp2p --ipp2p -j DROP
iptables -A FORWARD -m layer7 --l7proto bittorrent -j DROP

mydebian:/usr/src/ipp2p-0.8.2# iptables -nvL
Chain INPUT (policy ACCEPT 1116 packets, 82622 bytes)
pkts bytes target prot opt in out source destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DROP all — * * 0.0.0.0/0 0.0.0.0/0 ipp2p v0.8.2 –ipp2p
0 0 DROP all — * * 0.0.0.0/0 0.0.0.0/0 LAYER7 l7proto bittorrent

Chain OUTPUT (policy ACCEPT 664 packets, 91251 bytes)
pkts bytes target prot opt in out source destination

mydebian:/usr/src/ipp2p-0.8.2# lsmod | egrep 'ipp2p|layer7'
xt_layer7 11236 1
nf_conntrack 62720 2 nf_conntrack_ipv4,xt_layer7
ipt_ipp2p 6848 1
x_tables 14372 3 xt_layer7,ipt_ipp2p,ip_tables

มกราคม 15, 2008

การติดตั้ง Gentoo 2007.0

Filed under: Linux, gentoo — suchart @ 2:52 pm

มาช้าไปหน่อย แต่ก็ยังดีกว่าไม่มา ท่ามกลางกระแสข่าวที่ไม่ค่อยจะสู้ดีนัก ของ Gentoo ผมขอสวนกระแสซักหน่อย

ผมว่า Gentoo มันสอนอะไรหลายๆ อย่างในตอนติดตั้ง ใครที่เคยเล่นลีนุกซ์ตัวอื่นมาแล้ว น่าจะลองติดตั้งดู จะได้รสชาติไปอีกแบบ แต่เสียเวลาติดตั้งนานหน่อย

อ่านต่อ http://suchart.wordpress.com/gentoo-20070-installation/

มกราคม 11, 2008

vi (vim) จดคำสั่งไว้ กันลืม

Filed under: Linux, Unix — suchart @ 6:56 pm

ผมมักจะใช้ vi ในการแก้ไขไฟล์ แต่ก็ไม่ได้เชี่ยวชาญอะไร คำสั่งมันเยอะมาก แต่ผมใช้จริงไม่เท่าไร แต่พอไม่ได้ใช้นานๆ มันก็มักจะลืมบางคำสั่ง ทำให้เสียเวลา หน้านี้ก็ขอจดคำสั่งที่ตัวเองใช้บ่อยๆ ที่พอจะจำได้ไว้ก่อน เอาไว้เตือนความจำ

อ่านต่อ ที่ http://suchart.wordpress.com/vi-vim/

มกราคม 10, 2008

เล่นกับ Linux Wireless Router

Filed under: Linux — suchart @ 10:07 am

ช่วงนี้รู้สึกเบื่อๆ เพราะโน้ตบุคเจ้าปัญหาของผม HP dv2109tx มันพังอีกแล้ว กำลังส่งซ่อมอยู่ นี่ดีนะที่ไวต้วทัน ซื้อประกันเพิ่มไว้ก่อน พึ่งปีกับอีก 1 เดือนเท่านั้นเอง เอาเครื่องไปส่งซ่อมก็เลยแวะพันทิพธ์ หาอะไรเล่นดีกว่า พอดีกำลังอยากได้ wireless router ของ asus รุ่น WL-500gP มันเป็นลีนุกซ์ มี usb ด้วย 2 port แล้วก็สามารถลง 3rd party firmware ได้ด้วย รุ่นนี้เคยขาดตลาดมาแล้ว เพราะมีคนไปโพสต์เชียร์ไว้เยอะ ราคาเริ่มจาก 3000 ต้นๆ จนพุ่งไปถึง 4000 กว่าๆ แถมยังหาซื้อยากอีกต่างหาก แต่ขณะเดียวกันก็มีคนประกาศขายมือสองเยอะเหมือนกัน เพราะงง ไม่เป็นลีนุกซ์

ผมเองมี Linksys WRT54GL ที่เป็นลีนุกซเหมือนกันอยู่แล้ว แต่มันเล่นไม่ค่อยมัน เพราะว่า flash memory มันแค่ 4 mb ลงอะไรไม่ค่อยได้ แถมไม่มี usb port อีกต่างหาก

ไปเจออยู่ 3 ร้าน ราคา 3590, 3600 แล้วก็ 3550 ร้านสุดท้าย เอาละเมื่อยแล้ว เห็นเพื่อนบอกว่าที่ฟอร์จูนขายตั้ง 3750

คนอื่นเขาเล่น linux embeded พวกนี้มาตั้งนานแล้ว แต่ผมไม่รู้ไปอยู่ไหนมา พึ่งจะมาเล่น

กลับมาถึงบ้าน ก็เปิดเครื่องเข้าไปดูหน้าเว็บแอดมินของ asus ซะหน่อย แล้วก็อัพเฟิร์มแวร์ของ asus ไปหนึ่งตัว มันไม่ค่อยจะมีอะไรให้เล่น ก็อัดเฟิร์มแวร์ x-wrt เข้าไปซะ ความสนุกและปวดหัวก็กำลังเริ่มต้น

หลังใส่เฟิร์มแวร์ x-wrt ไปแล้ว ปรากฎว่าไม่สามารถ ติดต่อผ่านเน็ตเวิร์คกับเราต์เตอร์ได้เลย หาอยู่ตั้งนานก็พบว่ามันเป็นที่ ถ้าต่อสายแลนจากแวนพอร์ตของเราเตอร์ไปยังโมเด็มของ Linksys AM300 (จริงๆ แล้วมันก็ทำงานเป็นเราต์เตอร์ได้ด้วย) เน็ตเวิร์คของลีนุกซ์จะมีปัญหา สาเหตุน่าจะมาจาก dhcp client ของเราต์เตอร์ เพราะโดยดีฟอลต์แล้วมันจะรันอัตโนมัติ หลังติดตั้งเฟิร์มแวร์เสร็จใหม่ๆแล้วมันรีบูตเครื่อง วิธีแก้ไขก็คือต้องถอดสายแวนออกก่อน แล้วเซตให้ แวนเป็นแบบ pppoe ก่อน แล้วรีบูตเครื่อง เสร็จแล้วค่อยต่อสายแวน

X-wrt เป็นส่วนขยายของ OpenWrt โดยหลักๆ แล้วก็คือเพิ่มในส่วนของ web admin interface ส่วน OpenWrt นั้นจะคอนฟิกผ่านไฟล์คอนฟิกโดยตรง ทั้งสองเฟิร์มแวร์ สามารถติดตั้งแพคเกจเพิ่มได้ โดยใช้คำสั่ง ipkg

ที่ผมชอบมากก็คือ มันสนับสนุน layer7-filter , ipp2p และยังสามารถติดตั้งแพคเกจ ต่างๆ เช่น ip , tc และ iptables และ kernel module ที่เกี่ยวข้องต่างๆ ได้เลย โดยใช้ ipkg install ตามด้วยชื่อแพคเกจ

Links

ASUS WL-500gP

Linksys WRT54GL

http://openwrt.org/

http://wiki.openwrt.org/TableOfHardware

http://x-wrt.org/

มกราคม 5, 2008

คิดถึง gentoo

Filed under: Linux, gentoo — suchart @ 5:04 am

เห็น iptables patch ที่คุณ rokoman ให้ลิงค์มา แล้วทำให้คิดถึง gentoo linux เลยลองแอบไปดู package (source) repository ของมันมา ก็พบว่ามันมี ทั้ง ipp2p และ layer7-filter อยู่ด้วย (และอื่นๆอีกมาก) เอากับเขาดิ ในขณะที่ตัวอื่นที่ผมเล่นๆมา ทั้งสาย redhat , debian ยังไม่ยักกะมี แต่ก็ไม่น่าแปลกใจเท่าไร เพราะว่า gentoo มันคอมไพล์และติดตั้งแพคเกจจาก source อยู่แล้ว

ผมเองเคยลง gentoo แค่ครั้งเดียว เมื่อนานมาแล้ว ตอนที่ยังบ้าพลัง เล่นพวกตระกูล BSD ทั้งหลายอยู่ ตอนนั้นยังไม่มี installer(ซึ่งยังไม่ค่อยจะเวิร์คซักเท่าไร) ยังจำฝังใจว่ามันเป็นโอเอสที่ลงยาก และเสียเวลามากที่สุดเท่าที่เคยลงมา พอมีภารกิจต้องให้ห่างหายจากลีนุกซ์ไปพักหนึ่ง ก็ยิ่งทำให้เกือบจะลืม gentoo ไปซะแล้ว สงสัยต้องหาเวลามาระลึกความหลังกับ gentoo บ้างซะแล้ว ว่าแต่ว่ายังมีแฟนๆ ของ gentoo อยู่แถวนี้บ้างหรือเปล่านี่?

มกราคม 1, 2008

screen - A screen manager that supports multiple logins on one terminal

Filed under: Debian, Linux, Ubuntu — suchart @ 11:52 am

screen ช่วยให้เราสามารถมีหน้าจอล็อกอินหลายๆ หน้าจอจากเทอร์มินัลเดียวได้ และสามารถเรียกใช้หน้าจอ screen ที่เคยเรียกใช้ค้างไว้แล้วได้ เหมาะอย่างยิ่งกับการใช้งานรีโมทผ่าน ssh or telnet

Redhat & Fedora Installation

# yum install screen

Debian & Ubuntu Installation

# apt-get install screen

การใช้งานแบบง่ายๆ

เรียกใช้โปรแกรม เพื่อสร้างหน้าจอเทอร์มินัลใหม่

# screen

Ctrl+a c สร้างหน้าจอล็อกอินใหม่ จากเทอร์มินัลเดิม

Ctrl+a n เรียกใช้หน้าจอล็อกอินถัดไปที่เคยสร้างไว้แล้ว วนไปเรื่อยๆ

Ctrl+a p  เรียกใช้หน้าจอล็อกอินก่อนหน้า

ถ้าต้องการเรียกใช้หน้าจอเทอร์มินัลของ screen ที่เคยใช้ค้างอยู่แล้ว

# screen -r

หรือ

# screen -d -r

ข้อมูลเพิ่มเติม

# screen --help

# man screen

ธันวาคม 27, 2007

Kernel 2.6.23.12 + iptables 1.4.0 (1.3.8) + L7-filter + ipp2p on Ubuntu 7.10 Server

Filed under: Debian, Linux, Ubuntu — suchart @ 7:18 pm

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

(: ขอพักก่อนนะครับ !

 

ธันวาคม 17, 2007

Traffic Shaping on Linux with tc , iptables and ipp2p

Filed under: Linux — suchart @ 11:14 am

Traffic Shaping on Linux Gateway with tc , iptables and ipp2p

ฝากแปะไว้ก่อนกันลืมนะครับ

modprobe ipt_ipp2p

tc qdisc del dev eth1 root <== eth1 = internal interface
tc qdisc add dev eth1 root handle 1: htb
tc class add dev eth1 parent 1: classid 1:1 htb rate 900kbit <== max dl 900 kbits

tc class add dev eth1 parent 1:1 classid 1:11 htb rate 300kbit ceil 750kbit prio 2 <== p2p dl 300-750 kbits
tc class add dev eth1 parent 1:1 classid 1:12 htb rate 300kbit ceil 750kbit prio 1 <== www dl 300-750 kbits
tc class add dev eth1 parent 1:1 classid 1:13 htb rate 100kbit ceil 150kbit prio 0 <== ssh dl 100-150 kbits

tc qdisc add dev eth1 parent 1:11 handle 11: sfq perturb 10
tc qdisc add dev eth1 parent 1:12 handle 12: sfq perturb 10
tc qdisc add dev eth1 parent 1:13 handle 13: sfq perturb 10

tc filter add dev eth1 parent 1:0 prio 2 protocol ip handle 11 fw flowid 1:11 <== handle match –set-mark
tc filter add dev eth1 parent 1:0 prio 1 protocol ip handle 12 fw flowid 1:12 <== flowid match classid
tc filter add dev eth1 parent 1:0 prio 0 protocol ip handle 13 fw flowid 1:13

iptables -A PREROUTING -t mangle -p tcp -j CONNMARK –restore-mark
iptables -A PREROUTING -t mangle -p tcp -m mark ! –mark 0 -j ACCEPT
iptables -A PREROUTING -t mangle -p tcp -m ipp2p –ipp2p -j MARK –set-mark 11 <== match and mark p2p
iptables -A PREROUTING -t mangle -p tcp -m mark –mark 1 -j CONNMARK –save-mark

iptables -A PREROUTING -t mangle -p tcp –sport 80 -j MARK –set-mark 12 <== mark http
iptables -A PREROUTING -t mangle -p tcp –sport 22 -j MARK –set-mark 13 <== mark ssh

Links

iptables Tutorial

http://ipp2p.org/documents/README

http://lartc.org/howto/lartc.qdisc.filters.html

HTB Linux queuing discipline manual - user guide

ธันวาคม 10, 2007

netstat-nat - A tool that display NAT connections

Filed under: Debian, Linux, Ubuntu — suchart @ 7:07 am

apt-get install netstat-nat

root@myubuntu:~# netstat-nat
Proto NATed Address                  Destination Address            State
tcp   192.168.100.11:1048            mail3.rootly.com:www           TIME_WAIT
tcp   192.168.100.11:1043            ded135-fbsd-174-35.netsoni:www ESTABLISHED
tcp   192.168.100.11:1046            hk-in-f164.google.com:www      ESTABLISHED
tcp   192.168.100.11:1042            ded135-fbsd-174-35.netsoni:www ESTABLISHED
tcp   192.168.100.11:1044            ded135-fbsd-174-35.netsoni:www ESTABLISHED
tcp   192.168.100.11:1047            64.233.189.99:www              ESTABLISHED
tcp   192.168.100.11:1049            mail3.rootly.com:www           TIME_WAIT
udp   192.168.100.11:1035            dns2.asianet.co.th:domain      ASSURED
udp   192.168.100.11:1045            dns2.asianet.co.th:domain      UNREPLIED
root@myubuntu:~# netstat-nat -n
Proto NATed Address                  Destination Address            State
tcp   192.168.100.11:1048            38.98.18.85:80                 TIME_WAIT
tcp   192.168.100.11:1043            66.180.174.35:80               ESTABLISHED
tcp   192.168.100.11:1046            64.233.189.164:80              TIME_WAIT
tcp   192.168.100.11:1042            66.180.174.35:80               TIME_WAIT
tcp   192.168.100.11:1044            66.180.174.35:80               ESTABLISHED
tcp   192.168.100.11:1047            64.233.189.99:80               TIME_WAIT
tcp   192.168.100.11:1049            38.98.18.85:80                 TIME_WAIT
udp   192.168.100.11:1035            203.144.207.49:53              ASSURED
udp   192.168.100.11:1045            203.144.207.49:53              UNREPLIED
root@myubuntu:~#

Kernel 2.6.23.9 + iptables 1.3.8 + L7-filter + ipp2p on Ubuntu 7.10 Server

Filed under: Linux, Ubuntu — suchart @ 12:53 am

โน้ตคำสั่งต่างๆ ที่ใช้ไว้ก่อนกันลืม

===============================================================

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://www.ipp2p.org/

http://l7-filter.sourceforge.net/

http://ubuntuforums.org/showthread.php?t=56835

http://www.kernel.org/

http://www.netfilter.org/

ธันวาคม 8, 2007

apt-get ผ่าน proxy

Filed under: Debian, Linux, Ubuntu — suchart @ 4:26 pm

export http_proxy=http://myusername:mypassword@myproxy:myproxy_port

sudo apt-get update

sudo apt-get install xxx

หน้าต่อไป »

บลอกที่ WordPress.com .