การบล๊อก Bittorrent
ช่วงเวลาอันแสนเศร้า
การติดตั้ง SARG บน Slackw ...
การทำ Gateway บน Slackwar ...
เหรียญในมือ
การบีบอัดไฟล์บนระบบปฏิบัต ...
การติดตั้ง webmin on ubun ...
การติดตั้ง sshd on FreeBS ...
คำสั่งช่วยในการค้นหาคำต่า ...
NAT+Squid+Transparent Pro ...
Start/Stop and Restart Se ...
วิธีตรวจดูสเปคของเซิร์ฟเว ...
คำสั่งสำหรับผู้ใช้พื้นฐาน ...
ลืม password ฐานข้อมูล My ...
การ kill process

1 | 2 |>>
All (10)
default (10)
All (17)
default (0)
FreeBSD (3)
Linux_General (6)
Slackware (3)
Story of the year (2)
Ubuntu (3)
.name :
.url :
.message :
.security code :
สมัครสมาชิก | Login

 


การบล๊อก Bittorrent
2007-08-27 08:41:25

L7-filter (Application Layer Packet Classifier for Linux) For Slackware 10.2 kernel 2.6.13
Bittorrent เป็นปัญหาของหลายองค์กร ถ้าทุกคนใช้บริการตามปกติ ก็จะไม่พบปัญหาเรื่องความเร็ว แต่ถ้าในองค์กรมีคนกลุ่มหนึ่งใช้บริการ หรือช่องสัญญาณสื่อสารมากกว่าสมาชิกคนอื่นมาก ความเร็วที่สมาชิกคนอื่นในระบบได้รับจะลดลง เช่น
บริษัทแห่งหนึ่งใช้บริการ ADSL และมีคอมพิวเตอร์ในเครือข่าย 5 เครื่อง
สมาชิกสามารถใช้บริการพร้อม ๆ กันด้วยความเร็วที่
ทุกคนพึงพอใจ ต่อมามีสมาชิกคนหนึ่งใช้บริการ
Bittorrent ดาวน์โหลดหนัง 10 เรื่อง แล้วเปิดเครื่องของตนให้เพื่อนในอินเทอร์เน็ตจากทั่วโลก
เข้ามาดาวน์โหลดหนังทั้ง 10 เรื่อง ผลกระทบที่ชัดเจนคือ เพื่อนอีก 4 คนในเครือข่ายของบริษัทจะใช้บริการอินเทอร์เน็ตได้ช้าลง
ถ้าท่านเป็น 1 ใน 4 คนที่ได้รับผลกระทบ ท่านจะทำอย่างไร
สำหรับ admin อย่างเราต้อง block หรือป้องกันไม่ให้ใช้งานได้
ซึ่ง Bittorrent  เป็นโปรแกรมที่มีการสุ่ม port ออก  และในปัจจุบันได้มี โปรแกรมอีกมากมาย
เช่น msn, qq, skype ซึ่งโปรแกรมเหล่านี้ม
ีการพัฒนาขึ้นโดยมีการสุ่ม port ออก ซึ่งเราจะไม่สามารถ block หรือ ห้ามไม่ใช้ใช้งานได้เลย ดังนั้นเป็นเหตุใหญ่ที่เราต้องทำการ ติดตั้ง L7-filter (Application Layer Packet Classifier for Linux) เพื่อควบคุมการใช้งานในระดับของ Layer 7
1. เข้าไปยังไดเรกทรอรี่ usr/src โดยใช้คำสั่ง
    #cd /usr/src
2. ทำการดาวน์โหลดแพ็คเก็จต่างๆ ที่ใช้ในการติดตั้งดังนี้
    ดาว์โหลด iptables-1.3.6 หรือเวอร์ชั่นที่ใหม่กว่าที่เว็บไซต์
    #wget http://packages.thaislack.com/L7-protocals/iptables-1.3.6.tar.bz2
    ดาว์โหลด netfilter-layer7-v2.0 หรือเวอร์ชั่นที่ใหม่กว่าที่เว็บไซต์
    #wget http://packages.thaislack.com/L7-protocals/netfilter-layer7-v2.0.tar.gz
    ดาว์โหลด l7-protocols-2007-01-08  หรือเวอร์ชั่นที่ใหม่กว่าที่เว็บไซต์
    #wget http://packages.thaislack.com/L7-protocals/l7-protocols-2007-01-08.tar.gz
     ดาว์โหลด kernel  หรือเวอร์ชั่นที่ใหม่กว่าที่เว็บไซต์
    #wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.13.tar.bz2
3. ทำการขยายไฟล์ต่างๆ ที่ดาวน์โหลดเสร็จเรียบร้อยแล้ว
    #tar jxvf iptables-1.3.6.tar.bz2     
    #tar zxvf netfilter-layer7-v2.0.tar.gz
    #tar zxvf l7-protocols-2007-01-08.tar.gz
    #tar xjf linux-2.6.13.1.tar.bz2
4. ตรวจสอบ version kernel ของ Linux ที่ใช้อยู่ โดยใช้คำสั่ง
    #uname -a
    จะแสดงข้อมูลดังนี้
    Linux ns 2.6.13 #1 Tue Sep 6 17:56:37 PDT 2005 i686 unknown unknown GNU/Linux
5. ทำการสร้าง link ให้กับ Linux
    #ln -s linux-2.6.13.1 linux
    #cd /usr/src/linux
    #patch -p1 < /usr/src/netfilter-layer7-v2.0/kernel-2.6.13-2.6.14-layer7-2.0.patch
    #make menuconfig
ทำการเลือกหัวข้อต่างๆดังนี้
/////////////////////////////////////////////////////////////
Code maturity level options --> [*] Prompt for development and/or incomplete code/drivers
Networking --> Networking options -->
    [*] Network packet filtering (replaces ipchains) -->
        IP: Netfilter Configuration -->
            <M> Connection tracking (required for masq/NAT)
            [*] Connection tracking flow accounting
            <M> IP tables support (required for filtering/masq/NAT)
            <M> Layer 7 match support
หมายเหตุ หากทำการ patch สำเร็จจะมีฟังก์ชั่น Layer 7 match support ให้เลือก

ถ้าหากการ patch ไม่สำเร็จจะไม่มีฟังก์ชั่น Layer 7 match support ให้เลือก ให้ทำการ patch ใหม่อีกครั้ง
เมื่อทำการเลือกเสร็จแล้วให้ทำการบันทึก และ Exit ออกมาครับ จากนั้นใช้คำสั่งดังต่อไปนี้
    #make dep
    #make clean
    #make bzImage
    #make modules
    #make modules_install
หรือจะใช้คำสั่ง
    #make dep ; make clean ; make bzImage ; make modules; make modules_install

6. ทำการสร้าง Lilo เพื่อใช้ในการบูตระบบโดยใช้คำสั่ง ดังนี้
    #cp System.map /boot/System-l7.map
    #cp .config /boot/config-l7
    #cp arch/i386/boot/bzImage /boot/vmlinuz-l7
    #cd /boot
    #ln -sf System-l7.map System.map
    #ln -sf config-l7 config
    #pico /etc/lilo.conf
        เพิ่มคำสั่งบนบรรทัด
        image = /boot/vmlinuz
    #----------------------------------------------------#
        image = /boot/vmlinuz-l7
        root = /dev/hda1  #hda ที่ใช้
        label = Linux-l7
        read-only
    #--------------------------------------------------#
จากนั้นบันทึกแล้ว Exit ออกมาครับ แล้วทำการพิมพ์คำสั่งดังนี้
    #lilo
     #reboot

ติดตั้ง iptables 1.3.6
7. ย้ายไปยังไดเรกทรอรี่ /usr/src โดยใช้คำสั่ง
    #cd /usr/src
8. จากนั้นทำการสร้าง link ใหม่ให้กับ iptables 1.3.6
    #ln -sf iptables-1.3.6 iptables
9. เมื่อสร้างลิงค์เสร็จเรียบร้อยแล้ว ให้เข้าไปยังไดเรกทรอรี่ของ iptable โดยใช้คำสั่ง
    #cd iptables
10. ทำการ patch โดยใช้คำสั่ง
    #patch -p1 < /usr/src/netfilter-layer7-v2.0/iptables-layer7-2.0.patch
    #chmod +x extensions/.layer7-test
11. ทำการ remove iptables ของเก่าออกก่อนโดยใช้คำสั่ง
    #removepkg iptables
12.
    #export KERNEL_DIR=/usr/src/linux
    #export IPTABLES_DIR=/usr/src/iptables
    #make PREFIX=/usr/src/iptables/ LIBDIR=/usr/local/lib/ BINDIR=/sbin
    #make PREFIX=/usr/src/iptables/ LIBDIR=/usr/local/lib/ BINDIR=/sbin install

ติดตั้ง l7-protocols-2007-10-08
13. ย้ายไปยังไดเรกทรอรี่ /usr/src/l7-protocols-2007-01-08
    #cd /usr/src/l7-protocols-2007-01-08
14. ทำการติดตั้ง โดยใช้คำสั่งดังนี้
    #make install
15. จากนั้น ใช้คำสั่ง
    #lsmod
ถ้าแสดงข้อมูลดังนี้แสดงว่ามีการโหลด module layer7 แล้ว
-----------------------------------------------------------------------------------
Module                  Size  Used by
ipt_layer7             12588  0
ip_tables              18560  6 ipt_layer7,iptable_mangle,ipt_REDIRECT,ipt_MASQUERADE,iptable_nat,iptable_filter
-----------------------------------------------------------------------------------
17.จากนั้นเพิ่มคำสั่งในไฟล์ ld.so.conf โดยใช้คำสั่ง
    #pico /etc/ld.so.conf
    เพิ่มคำสั่งดังนี้
        /usr/local/iptables/extensions
    จากนั้นทำการบันทึกและออกจากโปรแกรม pico แล้วพิมพ์คำสั่งดังนี้
    #ldconfig
    #init 6
18. ตรวจสอบว่า Layer 7 ว่าพร้อมทำงานหรือยัง โดยใช้คำสั่ง
    #iptables -m layer7 --help
ถ้าได้ผลตามนี้ก็ขอแสดงความยินดีด้วยครับ ^^
iptables v1.3.6
Usage: iptables -[AD] chain rule-specification [options]
       iptables -[RI] chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LFZ] [chain] [options]
       iptables -[NX] chain
       iptables -E old-chain-name new-chain-name
       iptables -P chain target [options]
       iptables -h (print this help information)

Commands:
Either long or short options are allowed.
  --append  -A chain            Append to chain
  --delete  -D chain            Delete matching rule from chain
  --delete  -D chain rulenum
                                Delete rule rulenum (1 = first) from chain
  --insert  -I chain [rulenum]
                                Insert in chain as rulenum (default 1=first)
 LAYER7 match v1.3.6 options:
--l7dir <directory>  : Look for patterns here instead of /etc/l7-protocols/
                       (--l7dir must be specified before --l7proto if used!)
--l7proto [!] <name> : Match the protocol defined in /etc/l7-protocols/name.pat

การใช้งาน L7-filter นำคำสั่งดังต่อไปนี้ไปใส่ไว้ในไฟล์ /etc/rc.d/rc.local เพื่อทำให้มันสตาร์ตทุกครั้งที่ Reboot เครื่อง
iptables -I FORWARD -s 192.168.2.3 -m time --timestart 8:00 --timestop 18:00 --days Mon,Tue,Wed,Thu,Fri -j ACCEPT
#. counterstrike
iptables -t mangle -A POSTROUTING -m layer7 --l7proto counterstrike -j DROP
#bittorrent
iptables -t mangle -A POSTROUTING -m layer7 --l7proto bittorrent -s 192.168.0.0/16 -j DROP
#msnmessenger
iptables -t mangle -A POSTROUTING -m layer7 --l7proto msnmessenger -s 192.168.0.0/16 -j DROP
#. QQ
iptables -t mangle -A POSTROUTING -m layer7 --l7proto qq -s 192.168.0.0/16 -j DROP
#. EXE
iptables -t mangle -A POSTROUTING -m layer7 --l7proto exe -s 192.168.0.0/16 -j DROP
#Fasttrack
iptables -t mangle -A POSTROUTING -m layer7 --l7proto fasttrack -s 192.168.0.0/16 -j DROP
#Examples.
iptables -A FORWARD -m iprange --src-range 192.168.1.5-192.168.1.124 -j ACCEPT
iptables -A FORWARD -m iprange --dst-range 10.0.0.0-10.5.255.255.255 -j ACCEPT
#. Bittorrent
iptables -t mangle -A POSTROUTING -m layer7 --l7proto bittorrent -s 192.168.0.0/16 -j DROP
#. Blocco di Download Audio/Video   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto fasttrack -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto edonkey -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto gnutella -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto napster -j DROP   
#. Blocco di Accesso Audio/Video   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto audiogalaxy -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto httpaudio -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto http-itunes -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto httpvideo -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto quicktime -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto shoutcast -j DROP   
#. Blocco di Download di file con estensioni particolari   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto exe -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto ogg -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto flash -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto zip -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto rar -j DROP   
#. Blocco di sistemi di Chat/Scambio Files   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto msnmessenger -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto aim -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto msn-filetransfer -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto irc -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto jabber -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto skypeout -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto skypetoskype -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto qq -j DROP   
#. Blocco di sistemi di Giochi Online   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto battlefield2 -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto doom3 -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto halflife2-deathmatch -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto quake-halflife -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto quake1 -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto worldofwarcraft -j DROP   
iptables -t mangle -A POSTROUTING -m layer7 --l7proto xboxlive -j DROP

#######################
ตรวจสอบผลการบล็อกโดยใช้คำสั่ง
#######################
iptables -L -t mangle
จะได้ผลดังตัวอย่ามีการบล็อก Chat เช่น msn irc jabber skype qq เป็นต้น
------------------------------------------------------------------------
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
DROP       0    --  anywhere             anywhere            LAYER7 l7proto msnmessenger
DROP       0    --  anywhere             anywhere            LAYER7 l7proto aim
DROP       0    --  anywhere             anywhere            LAYER7 l7proto msn-filetransfer
DROP       0    --  anywhere             anywhere            LAYER7 l7proto irc
DROP       0    --  anywhere             anywhere            LAYER7 l7proto jabber
DROP       0    --  anywhere             anywhere            LAYER7 l7proto skypeout
DROP       0    --  anywhere             anywhere            LAYER7 l7proto skypetoskype
DROP       0    --  anywhere             anywhere            LAYER7 l7proto qq
-----------------------------------------------------------------------------
#########################################
หมายเหตุสำหรับผู้ที่คอมไพล์ kernel ไม่ผ่านไม่ต้องตกใจครับ แก้ไขดังนี้ครับ
#########################################
1. ให้จำตำแหน่ง patition ที่เป็น patition ในการ boot ระบบว่าอยู่ที่ patition ไหน ตรวจสอบง่ายด้วยใช้คำสั่ง
df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.4G  4.5G  4.9G  48% /
/dev/sda3             764M   33M  732M   5% /tmp
/dev/sda4             125G  3.8G  121G   4% /home
พาทิชั่นที่ใช้ในการ boot อยู่ที่ตำแหน่ง / คือ /dev/sda2

2. ใส่แผ่นติดตั้ง slackware 10.2 แผ่นที่ 1 ลงไป แล้วทำการ boot เครื่องใหม่ด้วยให้ boot จากแผ่น cdrom
3. เมื่อถึงตำแหน่ง boot: ให้พิมพ์  test26.s root=/dev/sda2 noinitrd ro แล้วเครื่องก็จะสามารถ boot ได้
4. ทำให้การแก้ไข kernel โดยให้ใช้ kernel เก่าไปก่อนแล้วค่อย คอมไพล์ใหม่อีกที
####
end
####
Reference : www.thaislack.com
ป้าย : การบล๊อกBittorrent
Dictionary : การบล๊อกBittorrent



อ่านอย่างเดียว
ไม่ต้องดื่ม
ก็ "เมา" ค่ะ
by : kok [2007-08-27 13:32:58]


ไม่มึนหรอกครับ เมาเลยยย
by : plakapongza [2007-08-27 17:32:56]


กรูจะโหลดอ่ะ ทำไม

55++

กวนตรีน ซะงั้นอ่ะ
by : lloliita [2007-08-28 13:26:44]


ลองใช้แล้วครับ ดีจริงๆ อิอิ
by : ky [2007-09-04 13:57:33]