使用iptables的功能擴展全面封殺P2P流量(不要重新編譯內(nèi)核及Netfilter模塊)
Linux真是好東西啊!Linux系統(tǒng)不但穩(wěn)定,平臺相對安全,而且還是開放源代碼且是免費的,其中的iptables更是功能強大,所以筆者公司一直在用他做公司的內(nèi)部網(wǎng)關(guān), 并通過iptables 的設置做一些安全方面的初步設定.于是從網(wǎng)上查詢iptables資料,呵呵,很多網(wǎng)友已經(jīng)做過了相關(guān)的嘗試,并且由于P2P在網(wǎng)絡上的影響,使很多Linuxer們開發(fā)出了相關(guān)的patch,專門來應對P2P對網(wǎng)絡性能的不良影響,通過研究網(wǎng)上的絕大多數(shù)資料,看到很多種解決方法,見的最多的是使用netfilter的patch-o-matic-ng補定包,打上ipp2p的補丁,然后再編譯netfilter,還有就是先編譯內(nèi)核再結(jié)合多種軟件包再來完成這種功能等,所有的方法有一點是相同的,就是都必須先打上補丁后,要重新編譯內(nèi)核,然后才能使功能得的擴展,暫不說眾多的補丁如何正確的應用和重新編譯內(nèi)核步驟的紛雜,稍有不熟悉內(nèi)核編譯或者補丁應用就會造成有版本沖突,致使整個過程失敗.筆者使用網(wǎng)上的很多方法,反復測試,最后還是不能完全成功,總是有這樣那樣的錯誤,沖突!經(jīng)過了約一周的反復測試,和受到網(wǎng)上各位大俠的啟發(fā),終于發(fā)現(xiàn)了一種更簡單的方法可以完全實現(xiàn)對P2P流量的完全控制,該方法最大的特點是不用任何重新編譯內(nèi)核和模塊. 一.測試工作環(huán)境: RedHat Linux 9.0 內(nèi)核版本:2.4.20-8 二.需要的軟件包: 1.Netfilter的IPTABLES 1.2.9 下載位置: http://www./project ... ables-1.2.9.tar.bz2 得到軟件包為: iptables-1.2.9.tar.bz2 2. IP2PP 0.80 下載位置: http://www./downloads/ipp2p-0.8.0.tar.gz 得軟件包為: ipp2p-0.8.0.tar.gz 3. SourceForge的IPTABLES-P2P 下載位置: http:///projects/iptables-p2p 得到軟件包為: iptables-p2p-0.3.0a.tar.gz 三.版本選擇的說明: 由于對P2P下載軟件的限制主要是依靠ip2pp-0.8.0和iptables-p2p,所以選擇iptables和Linux內(nèi)核版本均要兼顧他們的實際需求,這樣主要是避免各種版本間的互相沖突,出現(xiàn)不可預知的錯誤. 首先ip2pp-0.8.0,也是目前發(fā)布的最新穩(wěn)定版本,從說明文檔可以看到 發(fā)布者在以下版本已經(jīng)測試通過: -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 ) 1.2.7a, 1.2.8, 1.2.9, 1.2.11, 1.3.0, 1.3.1 再看iptables-p2p最新版本是0.30a,從相關(guān)文檔資料中看到,最后更新日期大概是2004/03/06 22:39:00,而且明確的看到在iptables 1.2.9下測試通過,對Linux內(nèi)核的支持2.4也支持2.6, 但沒有明確哪個具體版本. 綜合以上信息筆者選了以上iptables1.2.9, kernel 2.4.20-8, 目的是避免以上兩個軟件包出現(xiàn)問題的可能性. 四.安裝軟件包 1.首先當然是你自己安裝好RedHat Linux 9.0, 這個我想非常簡單, 主要在分區(qū)時新手的問題多點,網(wǎng)上資料眾多,隨便拿個作為參考就可以了,如果比較懶的話就按Linux預先定制安裝就可以了! 2.登陸系統(tǒng)把兩個軟件包放到適合的位置,然后解壓縮 一般軟件的包的源碼都放在/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.so /lib/iptables/ 所有安裝工作完成了,是不是很簡單!:) 五.功能簡介 1.ipp2p的使用說明 #iptables -m ipp2p –help 關(guān)于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. 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),也有專門對準協(xié)議的控制(iptables-p2p),一切允許與否就看你的幾條命令了!:) 注:以上所有過程本人都經(jīng)過測試通過,沒發(fā)現(xiàn)任何問題,本人初次原創(chuàng),不足之處希望大家諒解,如果能對一些朋友有幫助,在下非常榮幸!另外本人參考過網(wǎng)上多篇文章,再此對他們表示感謝! 后記:寫這篇文章的目的并不是要求所有網(wǎng)絡管理人員全部屏蔽P2P下載軟件,本人也是P2P軟件使用的愛好者,但是使用軟件時從來都是先設置連接數(shù)量和下載速度限制,以免影響別人的網(wǎng)絡使用.由于深深感受到不加限制使用P2P下載軟件對整個網(wǎng)絡系統(tǒng)性能造成的嚴重影響,所以建議大家能在使用P2P下載軟件時考慮網(wǎng)絡環(huán)境,先設置連接數(shù)量和下載速度限制.同時也建議網(wǎng)絡管理同行們根據(jù)情況到最后再考慮是否完全屏蔽掉P2P. |
|