[新聞] 使用Iptables的功能擴展全面封殺P2P流量
http://0rz.tw/3f2WA
佈時間:2007.07.18 06:35 來源:賽迪網 作者:skid
Linux真是好東西啊!Linux系統不但穩定,平臺相對安全,而且還是開放源代碼且是免費的,
其中的iptables更是功能強大,所以筆者公司一直在用他做公司的內部網關, 並通過
iptables 的設置做一些安全方面的初步設定.於是從網上查詢iptables資料,呵呵,很多網
友已經做過了相關的嘗試,並且由於P2P在網路上的影響,使很多 Linuxer們開發出了相關
的patch,專門來應對P2P對網路性能的不良影響,通過研究網上的絕大多數資料,看到很多
種解決方法,見的最多的是使用 netfilter的patch-o-matic-ng補定包,打上ipp2p的補丁,
然後再編譯netfilter,還有就是先編譯內核再結合多種套裝軟體再來完成這種功能等,所
有的方法有一點是相同的,就是都必須先打上補丁後,要重新編譯內核,然後才能使功能得
的擴展,暫不說眾多的補丁如何正確的應用和重新編譯內核步驟的紛雜,稍有不熟悉內核編
譯或者補丁應用就會造成有版本衝突,致使整個過程失敗.筆者使用網上的很多方法,反復
測試,最後還是不能完全成功,總是有這樣那樣的錯誤,衝突!經過了約一週的反復測試,和
受到網上各位大俠的啟發,終於發現了一種更簡單的方法可以完全實現對P2P流量的完全控
制, 該方法最大的特點是不用任何重新編譯內核和模組。
一、測試工作環境:
RedHat Linux 9.0
內核版本:2.4.20-8
二、需要的套裝軟體:
1.Netfilter的IPTABLES 1.2.9
下載位置: http://www.netfilter.org/project ... ables-1.2.9.tar.bz2
得到套裝軟體為: iptables-1.2.9.tar.bz2
2. IP2PP 0.80
下載位置: http://www.ipp2p.org/downloads/ipp2p-0.8.0.tar.gz
得套裝軟體為: ipp2p-0.8.0.tar.gz
3. SourceForge的IPTABLES-P2P
下載位置: http://sourceforge.net/projects/iptables-p2p
得到套裝軟體為: iptables-p2p-0.3.0a.tar.gz
三、版本選擇的說明:
由於對P2P下載軟體的限制主要是依靠ip2pp-0.8.0和iptables-p2p,所以選擇iptables和
Linux內核版本均要兼顧他們的實際需求,這樣主要是避免各種版本間的互相衝突,出現不
可預知的錯誤.
首先ip2pp-0.8.0,也是目前發佈的最新穩定版本,從說明文檔可以看到
發佈者在以下版本已經測試通過:
-Linux-Kernels 2.6: 2.6.3, 2.6.4, 2.6.6
-Linux-Kernels 2.4: 2.4.18, 2.4.19, 2.4.20, 2.4.21, 2.4.22, 2.4.23, 2.4.26
-iptables (from netfilter.org) 1.2.7a, 1.2.8, 1.2.9, 1.2.11, 1.3.0, 1.3.1
再看iptables-p2p最新版本是0.30a,從相關文檔資料中看到,最後更新日期大概是
2004/03/06 22:39:00,而且明確的看到在iptables 1.2.9下測試通過,對Linux內核的支援
2.4也支援2.6, 但沒有明確哪個具體版本.
綜合以上資訊筆者選了以上iptables1.2.9, kernel 2.4.20-8, 目的是避免以上兩個套裝
軟體出現問題的可能性.
四、安裝套裝軟體
1.首先當然是你自己安裝好RedHat Linux 9.0, 這個我想非常簡單, 主要在分區時新手的
問題多點,網上資料眾多,隨便拿個作為參考就可以了,如果比較懶的話就按Linux預先定制
安裝就可以了!
2.登陸系統把兩個套裝軟體放到適合的位置,然後解壓縮
一般軟體的包的源碼都放在/usr/src下,我下載的套裝軟體都在這下面準備使用
#cd /usr/src
#tar xjvf iptables-1.2.9.tar.bz2
#tar zxvf ipp2p-0.8.0.tar.gz
#tar zxvf iptables-p2p-0.3.0a.tar.gz
3.升級IPTABLES
RedHat 9.0自帶的iptables版本是.1.2.7a,所以先升級iptables到1.2.9
#cd /usr/src/iptables-1.2.9
#export KERNEL_DIR=/usr/src/linux-2.4
#export IPTABLES_DIR=/usr/src/iptables-1.2.9
#make BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install
4.安裝IPP2P套裝軟體
#cd /usr/src/ipp2p-0.8.0
#make
#cp libipt_ipp2p.so /lib/iptables
#insmod ipt_ipp2p.o
5.安裝iptables-p2p套裝軟體
#cd /usr/src/iptables-p2p-0.3.0a
#cp –a /usr/src/iptables-1.2.9/include/* /usr/include
#make
#cp kernel/ipt_p2p.o /lib/modules/2.4.20-8/kernel/net/ipv4/netfilter
#cp iptables/libipt_p2p.o /lib/iptables/
所有安裝工作完成了,是不是很簡單!
五、功能簡介
1.ipp2p的使用說明
#iptables -m ipp2p –help
關於ipp2p段的說明:
IPP2P v0.8.0 options:
--ipp2p Grab all known p2p packets
--edk [TCP&UDP] All known eDonkey/eMule/Overnet packets
--dc [TCP] All known Direct Connect packets
--kazaa [TCP&UDP] All known KaZaA packets
--gnu [TCP&UDP] All known Gnutella packets
--bit [TCP&UDP] All known BitTorrent packets
--apple [TCP] All known AppleJuice packets
--winmx [TCP] All known WinMX
--soul [TCP] All known SoulSeek
--ares [TCP] All known Ares
Note that the follwing options will have the same meaning:
'--ipp2p' is equal to '--edk --dc --kazaa --gnu --bit --apple --winmx --soul
--ares'
IPP2P was intended for TCP only. Due to increasing usage of UDP we needed to
change this.
You can now use -p udp to search UDP packets only or without -p switch to
search UDP and TCP packets.
See README included with this package for more details or visit
http://www.ipp2p.org
Examples:
iptables -A FORWARD -m ipp2p --ipp2p -j MARK --set-mark 0x01
iptables -A FORWARD -p udp -m ipp2p --kazaa --bit -j DROP
iptables -A FORWARD -p tcp -m ipp2p --edk --soul -j DROP
2.iptables-p2p的使用說明
#iptables -m p2p –help
P2P段的說明:
P2P match v0.3.0a options:
--p2p-protocol [!] protocol[,...]
--p2p ...
match application-layer protocol
Valid p2p protocols:
fasttrack
gnutella
edonkey
dc
bittorrent
openft
OK,一切準備就緒,就等你使用了,有專門識別包類型的控制(ipp2p),也有專門對準協議的
控制(iptables-p2p),一切允許與否就看你的幾條命令了!
注:以上所有過程本人都經過測試通過,沒發現任何問題,本人初次原創,不足之處希望大家
諒解,如果能對一些朋友有幫助,在下非常榮幸!另外本人參考過網上多篇文章,再此對他們
表示感謝!
後記:寫這篇文章的目的並不是要求所有網路管理人員全部遮罩P2P下載軟體,本人也是P2P
軟體使用的愛好者,但是使用軟體時從來都是先設置連接數量和下載速度限制,以免影響別
人的網路使用.由於深深感受到不加限制使用P2P下載軟體對整個網路系統性能造成的嚴重
影響,所以建議大家能在使用P2P下載軟體時考慮網路環境,先設置連接數量和下載速度限
制.同時也建議網路管理同行們根據情況到最後再考慮是否完全遮罩掉P2P.
給文章原文出處http://jammyse.blogchina.com/5444126.html,那我的BLOG,開了很久了,
內容比較少,歡迎大家去參觀啊!
(責任編輯:淩雲通)
--
___ ____ ◤\◢\
◢\__ __ ◢◤\_ ◤\ ◢◤\__ ◤\ ◢\◢◤\ ◢◤\\/◢◤\
◢◤\◢◤\◢◤\ ◢◤\/ \/ \_\__ \/ ◢◤\\_\/ ◢◤\/ ◢◤\/
◢◤\◢◤\◢◤\/ ◢\/_◤\ ◤\__◢◤\ ◢◤\/ ◢\/ ◤\_\/
\_\/\_\/\_\/ \_\___\/ \/__\_\/ \_\/ \_\___\/ ψRockMetal
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.231.4.163