鳥哥的 Linux 私房菜-新手討論區

特別適合 Linux 新手的討論區
鳥哥的 Linux 私房菜首頁 | 鳥哥 / Study Area 主站特搜 | Study Area | 酷!學園 討論區
新手發文時必看之:鳥園的文章管理規則提問的智慧, 簡繁體轉換的問題
現在的時間是 2010-09-03 17:33

所有顯示的時間為 UTC + 8 小時




發表新文章 回覆主題  [ 26 篇文章 ] 
發表人 內容
 文章主題 : [分享]打造 Linux 具有 L7-Filter Function?
文章發表於 : 2005-03-18 17:13 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2002-08-13 10:46
文章: 52
來自: 北縣/新店市
感謝 study-area 站長 Netman 網中人提供資料
原文出處:
http://l7-filter.sourceforge.net/L7-HOWTO-Netfilter

觀念解說:
本程式是透過 iptables 指令導引至 kernal 做 l7 filter 分析,
不如說是行為特徵比對.舉例來說一般為了想讓公司內部的員工禁用 IM
軟體如 MSN 但往往只能針對連線 Server & port 做封鎖,但此軟體又會
嘗試走 proxy 方式做連線,讓能防不勝防!如今打造此核心程式後就能迎
刃而解!為何如此說?因該程式會讓第一個封包產生 ESTABLISHED 之後就
Drop 掉以後封包讓該程式無法再轉由 proxy 做連線.

所有要做特徵比對參考檔案皆位在 /etc/l7-protocols/protocols
目錄下,只要在命令內加入如此 --l7proto msnmessenger 就開始做分析!

我 OS 環境:
Redhat 9.0
Kernel: 2.4.20-42.9.legacy
iptables: 1.2.11

技 巧︰
1﹒抓的是 bz2 的壓縮﹐所以用 j 參數﹐
抓的是 gz 格式﹐ 就用 z 參數。
2﹒可藉由 yum update 參數更新至上述核心!或者手動方式自行下載
http://ftp.kh.edu.tw/Linux/Redhat/fedor ... ates/i386/
3﹒在移除舊版 iptables 時記得先行備份此檔 /etc/init.d/iptables
再執行 yum remove iptables
4﹒由於 fro_older_kernels\kernel-2.4-layer7-0.9.1.patch 此檔,
是針對 linux-2.4.26-stock 做 patch ,而我的核心碼確非該版故
只能手動修改相關檔案位置插入要新增程式碼!如以下所述。
5﹒定期更新 Protocol definitions 檔案即可!位置如下:
http://sourceforge.net/projects/l7-filter/
6﹒kernel 在 2.4.20-28.9 以後版本 QOS 已支援 HBT Function,只要重編
核心選取即可。差意點在與 iprouter2 元件中 tc 指令並不支援,
故 Redhat 9 必須 update 該套件才能用。(套件名稱如後所指!)
而 tc 一般在設計上只能針對單一 device 做設定,而往往申請 ADSL
皆是非對稱式,故在使用上︰將下載設為對內網卡(本例為 eth0),
上行設為對外網卡(本例為 eth1)。
7﹒在實例應用︰預設禁止使用 msn,只開放少數人使用。
其語法不能如此下︰
#iptables -t mangle -A POSTROUTING -m layer7 --l7proto msnmessenger -j DROP
結果是︰所有封包皆以啟動核心比對!因用 iptables -L -n 或者 iptables -t nat -L
查看發現它不會顯示在 rule 內,以至於在下任何 iptables 指令皆無效!正確做法如
下所述 案例二方式,誤犯我相同錯誤觀念:-)

8﹒
www.netfilter.org 下載核心 patch-o-matic-20030912.tar.bz2 包
就可以新增如下 Function 給予參考!
./runme base/iprange.patch

說明如下:
---------------------------------------------------------------------
Each patch is a new feature: many have minimal impact, some do not.
Almost every one has bugs, so I don't recommend applying them all!
-------------------------------------------------------
Testing... iprange.patch NOT APPLIED (2 missing files)
The base/iprange patch:
Author: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Status: Works

This patch makes possible to match source/destination IP
addresses against inclusive IP address ranges.

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
---------------------------------------------------------------------


~正式開始︰~
------------------------------------------------------------------------

~可先做此步驟︰
[root@linux2005 temp]# gunzip l7-protocols-2005-02-06.tar.gz
[root@linux2005 temp]# tar -xvf l7-protocols-2005-02-06.tar
[root@linux2005 l7-protocols-2005-02-06]# make install

內容說明︰
all:
@echo Nothing to compile, just run \'make install\'
@echo \(This just copies this directory into $(PREFIX)/etc/l7-protocols \)
install:
mkdir -p $(PREFIX)/etc/l7-protocols
cp -R * $(PREFIX)/etc/l7-protocols



~修正核心 patch
1、先解壓縮並做 kernel & iptables path
[root@linux2005 temp]# gunzip netfilter-layer7-v1.0.tar.gz
[root@linux2005 temp]# tar -xvf netfilter-layer7-v1.0.tar
[root@linux2005 temp]# cd netfilter-layer7-v1.0
[root@linux2005 netfilter-layer7-v1.0]# cd for_older_kernels/
[root@linux2005 for_older_kernels]# cp kernel-2.4-layer7-0.9.1.patch /usr/src/.

手動編修下列檔案修改內容,參考 kernel-2.4-layer7-0.9.1.patch
linux-2.4.26-stock/Documentation/Configure.help
linux-2.4.26-stock/include/linux/netfilter_ipv4/ip_conntrack.h
linux-2.4.26-stock/include/linux/netfilter_ipv4/ipt_layer7.h
linux-2.4.26-stock/net/ipv4/netfilter/Config.in
linux-2.4.26-stock/net/ipv4/netfilter/Makefile
linux-2.4.26-stock/net/ipv4/netfilter/ip_conntrack_core.c
linux-2.4.26-stock/net/ipv4/netfilter/ip_conntrack_standalone.c
linux-2.4.26-stock/net/ipv4/netfilter/ipt_layer7.c

~ mkdir regexp 目錄
linux-2.4.26-stock/net/ipv4/netfilter/regexp/regexp.c
linux-2.4.26-stock/net/ipv4/netfilter/regexp/regexp.h
linux-2.4.26-stock/net/ipv4/netfilter/regexp/regmagic.h
linux-2.4.26-stock/net/ipv4/netfilter/regexp/regsub.c

2、
[root@linux2005 src]# pwd
/usr/src
[root@linux2005 src]# ln -sf linux-2.4.20-42.9.legacy linux

3、開始核心編譯
[root@linux2005 linux-2.4]# pwd
/usr/src/linux-2.4
[root@linux2005 linux-2.4]# make mrproper <-- 去除 .o 的編譯過的檔案

相同版本核心編譯可借用原始 .config 設定檔︰
[root@linux2005 linux-2.4]# cp /boot/config-2.4.20-42.9.legacy /usr/src/linux-2.4/.config

[root@linux2005 linux-2.4]# make oldconfig
...
會顯現新的選項:
Layer 7 match support (EXPERIMENTAL) (CONFIG_IP_NF_MATCH_LAYER7) [N/m/?] (NEW) m
Layer 7 debugging output (EXPERIMENTAL) (CONFIG_IP_NF_MATCH_LAYER7_DEBUG) [N/y/?] (NEW) y
Buffer size for application layer data (256-65536) (CONFIG_IP_NF_MATCH_LAYER7_MAXDATALEN) [2048] (NEW) 2048
...
*** End of Linux kernel configuration.
*** Check the top-level Makefile for additional configuration.
*** Next, you must run 'make dep'.

核心重新選取︰
[root@linux2005 linux-2.4]# make menuconfig

[root@linux2005 linux-2.4]# make clean <-- 新的核心才需執行!
或者
[root@linux2005 linux-2.4]# make dep <-- 相同核心執行此步驟
!!重要!!
若使用 make dep 方式原有 /lib/modules 目錄下核心目錄不能
移除或更名!
---------------------------------------------------------
#make bzImage <--開始編譯核心!這個步驟很長,因核心是經過壓縮
放置位址 /usr/src/linux-2.4.20-20.7/arch/i386/boot/bzImage
#make modules <--開始編譯模組!
#make modules_install <--將模組資料安裝在 /lib/modules/'uname -r' 裡面
#make install <--將剛 bzimage 建立完成核心給他安裝上來!

4、
編修開機檔
[root@linux2005 linux]# cd /boot/grub
[root@linux2005 grub]# vi grub.conf
....
default=0
timeout=5

title Red Hat Linux (2.4.20-42.9.legacycustom)
root (hd0,0)
kernel /vmlinuz-2.4.20-42.9.legacycustom ro root=LABEL=/
initrd /initrd-2.4.20-42.9.legacycustom.img



~ Ipatbles Patch
[root@linux2005 src]# pwd
/usr/local/src
[root@linux2005 src]# tar -jxvf iptables-1.2.11.tar.bz2
[root@linux2005 src]# cp /temp/netfilter-layer7-v1.0/iptables-layer7-1.0.patch .
[root@linux2005 src]# patch -p1 < iptables-layer7-1.0.patch
patching file extensions/.layer7-test
patching file extensions/libipt_layer7.c
patching file extensions/libipt_layer7.man

[root@linux2005 extensions]# pwd
/usr/local/src/iptables-1.2.11/extensions
[root@linux2005 extensions]# cp /usr/local/src/extensions/* .
[root@linux2005 extensions]# cp /usr/local/src/extensions/.layer7-test .
[root@linux2005 extensions]# chmod 755 .layer7-test


[root@linux2005 src]# cd iptables-1.2.11/
附註:
需重編核心要執行下列步驟︰
[root@linux2005 iptables-1.2.11]# pwd
/usr/local/src/iptables-1.2.11
[root@linux2005 iptables-1.2.11]# make clean

正常方式︰
[root@linux2005 iptables-1.2.11]# make KERNEL_DIR= /usr/src/linux-2.4
[root@linux2005 iptables-1.2.11]# make install KERNEL_DIR= /usr/src/linux-2.4

安裝完後,要確認下列目錄有此檔案︰
iptables v1.2.11: Couldn't load match `layer7':/usr/local/lib/iptables/libipt_layer7.so


_使用方式︰
QoS to filter
iptables -t mangle -A POSTROUTING -m layer7 --l7proto imap -j MARK --set-mark 3

The number "3" is arbitrary. It can be any unsigned 32-bit integer. Then you can use tc
tc filter add dev eth0 protocol ip parent 1:0 prio 1 handle 3 fw flowid 1:3

當下此命令是所有 http protocol 皆被拒絕掉!
[root@linux2005 /]# iptables -t mangle -A POSTROUTING -m layer7 --l7proto http -j DROP


~ iptables 掛為 Deamon 模式
[root@linux2005 init.d]# chkconfig -h
chkconfig version 1.3.8 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset>)
[root@linux2005 init.d]# pwd
/etc/init.d
[root@linux2005 init.d]# chkconfig --add iptables
[root@linux2005 init.d]# chkconfig --level 3 iptables on

[root@linux2005 init.d]# locate iptables |more
/usr/local/sbin/iptables
/usr/local/sbin/iptables-save
/usr/local/sbin/iptables-restore

[root@linux2005 init.d]# cp /usr/local/sbin/iptables /sbin/.
因為 /etc/init.d/iptables 內定義執行程式是在 /sbin 目錄內


~ QOS __ HTTB
[root@linux2005 temp]# rpm -Uvh iproute-2.4.7-7.90.1.htb.i386.rpm
Preparing... ########################################### [100%]
1:iproute ########################################### [100%]
主要更新 iptables 內 tc 套件能支援 htb 模組.

[root@linux2005 rc.d]# ./hbt_ebt

QOS 查驗方式︰
# tc -s -d qdisc show dev eth1
# tc -s -d class show dev eth1

[root@linux2005 rc.d]# tc -s -d qdisc show dev eth1
qdisc sfq 8004: quantum 1514b limit 128p flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)

qdisc sfq 8003: quantum 1514b limit 128p flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)

qdisc htb 3: r2q 10 default 3 direct_packets_stat 0 ver 3.10
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)

[root@linux2005 rc.d]#


[root@linux2005 rc.d]# tc -s -d class show dev eth1
class htb 3:1 root rate 960Kbit ceil 1Mbit burst 2827b/8 mpu 0b cburst 2909b/8 mpu 0b level 7
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
lended: 0 borrowed: 0 giants: 0
tokens: 18853 ctokens: 18187

class htb 3:2 parent 3:1 leaf 8003: prio 0 quantum 8192 rate 640Kbit ceil 1Mbit burst 2418b/8 mpu 0b cburst 2909b/8 mpu 0b level 0
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
lended: 0 borrowed: 0 giants: 0
tokens: 24189 ctokens: 18187

class htb 3:3 parent 3:1 leaf 8004: prio 0 quantum 4096 rate 320Kbit ceil 512Kbit burst 2008b/8 mpu 0b cburst 2254b/8 mpu 0b level 0
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
lended: 0 borrowed: 0 giants: 0
tokens: 40179 ctokens: 28187

[root@linux2005 rc.d]#


_案例一︰透過 l7_filter 轉至 QOS (鎖住下載對內網卡 eth0) 執行方法︰

[root@linux2005 rc.d]# iptables -t mangle -A POSTROUTING -m layer7 --l7proto http -j MARK --set-mark 3
[root@linux2005 rc.d]# tc filter add dev eth0 protocol ip parent 3:1 prio 1 handle 3 fw flowid 3:3

結 果:
當導入 Qos 頻寬管理後包含在 IE 網頁上直接下載 .exe 檔案皆會被限頻在你
所定規則內,本例是導入 classid 3:3 規則頻寬則設限為 20 KB/秒 範圍內.


~ HBT_EBT 定義內容如下︰
DEV_1="eth0"
EXT_IF="97.24.2.250"

# Up:_128 Kbps For DEV_1 InterNet eth2
# ---------------------------------------------------------------------------
# 128 KByte x 8 = 1024 Kbit

tc qdisc del root dev $DEV_1
tc qdisc add dev $DEV_1 root handle 3:0 htb default 3
tc class add dev $DEV_1 parent 3:0 classid 3:1 htb rate 960kbit ceil 1024kbit

#
tc class add dev $DEV_1 parent 3:1 classid 3:2 htb rate 640kbit ceil 1024kbit
tc class add dev $DEV_1 parent 3:1 classid 3:3 htb rate 160kbit ceil 160kbit


_案例二︰限制單一 IP 97.24.2.22 使用 MSN 軟體

iptables -s 97.24.2.22 -t mangle -A POSTROUTING -m layer7 --l7proto msnmessenger -j DROP

﹒倘若規則成立則 Linux 主機上會顯示如下訊息︰
→ layer7: regexec positive: msnmessenger!

﹒也可由 /var/log/messages 檔案 log 內容得知!



Q&A:
1、重開機啟動後檢查 layer7 module 有無載入?如有!應出現如下訊息。

[root@linux2005 /]# lsmod
Module Size Used by Not tainted
cls_fw 3480 1 (autoclean)
ipt_MARK 1432 1 (autoclean)
ipt_layer7 11260 1 (autoclean)
...
ip_conntrack 27016 2 [ipt_layer7 ipt_MASQUERADE ip_conntrack_ftp ip_nat_ftp iptable_nat]
ip_tables 14648 8 [ipt_MARK ipt_layer7 ipt_MASQUERADE iptable_mangle iptable_filter iptable_nat]
...


2、By default, l7-filter looks at the first 8 packets or 2kB, whichever is
smaller. You can alter the number of packets through
/proc/net/layer7_numpackets. i.e. "echo "12" > /proc/net/layer7_numpackets".
如編譯完在 /proc/net 目錄下無此 layer7_numpackets 檔案,而又需此功能!

_作者回覆︰
Well, I have no idea why you aren't getting the proc file. Perhaps it is
because you are using a Redhat kernel and one of their patches breaks it.
If you really need a higher numpackets, you can modify the default value
in linux/net/ipv4/netfilter/ipt_layer7.c, recompile, reinstall.

Near the top:

static int num_packets = 8;


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-05-15 12:23 
離線
初來乍到小菜鳥
初來乍到小菜鳥

註冊時間: 2005-05-15 12:03
文章: 2
好文章


剛剛特別註冊給您回應


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-05-18 15:12 
離線
漸有心得的小鳥
漸有心得的小鳥

註冊時間: 2003-11-23 01:39
文章: 70
來自: TAIPEI
不推太可惜了.....
感謝大大分享

_________________
到底是我玩LINUX.....還是LINUX玩我


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-05-18 16:02 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-06-12 16:54
文章: 414
好文章~~
請問一下,除了來檔一些軟体,還可否有別的用途嗎~~
在企業的應用上,那位大大有點子也請指點一下(小弟想不太出來=.=")~~
謝謝了

_________________
轉戰oracle了,但心還是在linux


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-22 19:48 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2004-06-11 14:26
文章: 46
請問有人用 2.6.14 成功過嗎?
我使用 Cent OS 4.2 並下載 2.6.14核心編譯,
不過怎麼樣都出現下面三行:

kernel/intermodule.c:178: warning: `inter_module_register' is deprecated (declared at kernel/intermodule.c:38)
kernel/intermodule.c:179: warning: `inter_module_unregister' is deprecated (declared at kernel/intermodule.c:78)
kernel/intermodule.c:181: warning: `inter_module_put' is deprecated (declared at kernel/intermodule.c:159)

不知道有沒有人遇到同樣的問題?


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-22 22:36 
離線
鳥友俱樂部榮譽會員
鳥友俱樂部榮譽會員

註冊時間: 2002-08-22 10:05
文章: 590
來自: 芒果乾國度
apage 寫:
kernel/intermodule.c:178: warning: `inter_module_register' is deprecated (declared at kernel/intermodule.c:38)


先看看那個字是什麼意思.

沒編譯過 kernel 嗎? 應該不只這三個吧. 通常跑下來, 幾十個以上的 warning 都很正常吧. 沒有 error 就可以了.

_________________
[url=http://blog.teatime.com.tw/1]圖檔
Tommy 碎碎念...[/url]


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-24 10:08 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-08-29 10:03
文章: 329
安裝後執行 會在console端顯示過濾狀況
請問如何讓他不顯示在console及message
修改過/etc/syslog.conf 還是一樣


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-24 10:18 
離線
鳥友俱樂部榮譽會員
鳥友俱樂部榮譽會員

註冊時間: 2002-08-22 10:05
文章: 590
來自: 芒果乾國度
那要看你的 iptables 怎麼下的吧.
iptables 不會沒事寫一堆東西到 console 與 message 的.

_________________
[url=http://blog.teatime.com.tw/1]圖檔
Tommy 碎碎念...[/url]


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-24 13:10 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-08-29 10:03
文章: 329
twu2 寫:
那要看你的 iptables 怎麼下的吧.
iptables 不會沒事寫一堆東西到 console 與 message 的.


IPTABLES 並沒有把訊息傳到 log 只是把封包DROP而已


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-24 13:26 
離線
鳥友俱樂部榮譽會員
鳥友俱樂部榮譽會員

註冊時間: 2002-08-22 10:05
文章: 590
來自: 芒果乾國度
那也許我們用的 iptables 不同吧. 也許你的版本有特殊功能吧.
至少我管的好幾台機器上頭, 除非我要產生 log, 否則並不會有..

iptables-save 看看內容吧.

_________________
[url=http://blog.teatime.com.tw/1]圖檔
Tommy 碎碎念...[/url]


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-24 13:53 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-08-29 10:03
文章: 329
Generated by iptables-save v1.3.3
-A POSTROUTING -m layer7 --l7proto bittorrent -j DROP
-A POSTROUTING -m layer7 --l7proto edonkey -j DROP
-A POSTROUTING -m layer7 --l7proto code_red -j DROP
-A POSTROUTING -m layer7 --l7proto nimda -j DROP

關於L7的部份很單純就這樣
kernel 2.4.31 #1 SMP
l7-protocols-2005-09-12.tar.gz
netfilter-layer7-v2.0.tar.gz


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-24 15:11 
離線
鳥友俱樂部榮譽會員
鳥友俱樂部榮譽會員

註冊時間: 2002-08-22 10:05
文章: 590
來自: 芒果乾國度
這幾條本來就沒什麼問題啊. 不然你要不要把你的 iptables rule 全清掉, 只留這幾條看看還會不會有 log.

我不清楚你是怎麼設定的, 不過可以確定的是, 在我接觸的到的幾台機器中, 沒有一台的 iptables 會產生一堆 log 在 console 或 message 中 (不管是用那個 iptables 的模組).
唯一會產生大量的 log, 只在於下了某個 -j LOG 的指令來叫 iptables 產生時.

_________________
[url=http://blog.teatime.com.tw/1]圖檔
Tommy 碎碎念...[/url]


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-25 15:42 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-08-29 10:03
文章: 329
如果不加L7的過濾條件 就不會在console 或 message 中產生log
所以我比較肯定是L7過濾程式造成的


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-25 15:59 
離線
鳥友俱樂部榮譽會員
鳥友俱樂部榮譽會員

註冊時間: 2005-01-15 23:41
文章: 2805
來自: Say Ya (telnet://bbs.sayya.org)
sincat 寫:
如果不加L7的過濾條件 就不會在console 或 message 中產生log
所以我比較肯定是L7過濾程式造成的


出現怎樣的訊息?貼來看看?

==


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-26 21:52 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2004-06-11 14:26
文章: 46
我成功了,我使用的是 CentOS + 官方2.6.14.2 核心,
在編譯核心時原本是沒什麼問題,不過由於 libipt_layer7.so
這個檔案老是沒出來,才會懷疑到核心上面去。

待整理資料後會把整理的結果 Po 上來,
畢竟這篇日子有點久遠而且不太清楚,搜尋 Google 老是搜到這篇文,
其他的資料甚少,希望可以給後面的人一些參考。


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-30 12:50 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-08-29 10:03
文章: 329
kenduest 寫:
sincat 寫:
如果不加L7的過濾條件 就不會在console 或 message 中產生log
所以我比較肯定是L7過濾程式造成的


出現怎樣的訊息?貼來看看?

==


訊息如下

Nov 30 12:44:37 kernel: l7-filter gave up after 1795 bytes (11 packets):
Nov 30 12:44:37 kernel: head /uri-res/n2r?urn:sha1:pihxlmuj64ndmfqfj4pzu5pj
mwrdheor http/1.1 host: 61.225.34.155:5100 user-agent: mxie 0.6.1.0 (mxie 1.0.
1.8) listen-ip: xxx.xxx.x.xxx:5100 connection: keep-alive x-queue: 0.1 x-fea
tures: g2/1.0 x-gnutella-content-urn: urn:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor
alt-location: http://xxx.xxx.x.xxx:5100/uri-res/n2r?u ... j64ndmfqfj
4pzu5pjmwrdheor 2005-11-30t20:47z alt-location: http://202.178.188.236:7884/uri
-res/n2r?urn:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor 2005-11-30t19:39z alt-locati
on: http://61.229.171.116:5100/uri-res/n2r? ... pzu5pjmwrd
heor 2005-11-30t20:46z alt-location: http://218.169.232.13:7884/uri-res/n2r?urn
:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor 2005-11-30t19:50z alt-location: http://2
20.133.229.25:7884/uri-res/n2r?urn:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor 1970-01
-01t08:00z alt-location: http://218.187.194.89:7884/uri-res/n2r?urn:sha1:pihxlm
uj64ndmfqfj4pzu5pjmwrdheor 2005-11-30t20:4In hex: 68 65 61 64 20


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-30 14:25 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-07-20 12:04
文章: 509
來自: 汐止
sincat 寫:
kenduest 寫:
sincat 寫:
如果不加L7的過濾條件 就不會在console 或 message 中產生log
所以我比較肯定是L7過濾程式造成的


出現怎樣的訊息?貼來看看?

==


訊息如下

Nov 30 12:44:37 kernel: l7-filter gave up after 1795 bytes (11 packets):
Nov 30 12:44:37 kernel: head /uri-res/n2r?urn:sha1:pihxlmuj64ndmfqfj4pzu5pj
mwrdheor http/1.1 host: 61.225.34.155:5100 user-agent: mxie 0.6.1.0 (mxie 1.0.
1.8) listen-ip: xxx.xxx.x.xxx:5100 connection: keep-alive x-queue: 0.1 x-fea
tures: g2/1.0 x-gnutella-content-urn: urn:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor
alt-location: http://xxx.xxx.x.xxx:5100/uri-res/n2r?u ... j64ndmfqfj
4pzu5pjmwrdheor 2005-11-30t20:47z alt-location: http://202.178.188.236:7884/uri
-res/n2r?urn:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor 2005-11-30t19:39z alt-locati
on: http://61.229.171.116:5100/uri-res/n2r? ... pzu5pjmwrd
heor 2005-11-30t20:46z alt-location: http://218.169.232.13:7884/uri-res/n2r?urn
:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor 2005-11-30t19:50z alt-location: http://2
20.133.229.25:7884/uri-res/n2r?urn:sha1:pihxlmuj64ndmfqfj4pzu5pjmwrdheor 1970-01
-01t08:00z alt-location: http://218.187.194.89:7884/uri-res/n2r?urn:sha1:pihxlm
uj64ndmfqfj4pzu5pjmwrdheor 2005-11-30t20:4In hex: 68 65 61 64 20


會有這些訊息是因為你的核心,有把L7的debug模式編進去~~~不想看到的話~~請把核心中debug的option拿掉~~~


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-11-30 14:58 
離線
完全無畏的老鳥
完全無畏的老鳥

註冊時間: 2002-08-29 10:03
文章: 329
多謝指教
太感謝了


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-12-06 15:29 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2004-06-11 14:26
文章: 46
由於公司內不擋 P2P,有時候許多人在用的時候都很慢,
因而生起 QOS 的想法,
去網路上查了資料,發現需要重新編譯核心,
也罷!重編就重編吧!

於是我開始重邊核心...以下是成功的步驟略述:

1. 到 http://www.kernel.org/ 找 Kernel 最新版
2. 下載並解壓縮
3. 到 http://l7-filter.sourceforge.net/L7-HOWTO-Netfilter 下載 Layer 7 patch
4. 解壓縮 Kernel 與 Layer 7 patch
5. 下 patch 與 Kernel 的合體指令:patch -p1 < patch_name
6.在 Kernel 的目錄下輸入:
a.make mrproper
b.make clean
c.cp /boot/之前的config ./
d.make menuconfig
7.選擇核心選項,記住 network 裡面的 qos 與 Layer 7 選項要選好來。
8.選好後儲存離開
9.開始編譯
a.make bzImage
b.make modules
c.make modules_install
d.make install
10.順利的話重開機即可順利運作。

接著要重新安裝 iptables
只要照著 readme 安裝就可以了,
若編譯過後 iptables 底下
並沒有 libipt_layer7.so 的話,
(重新安裝後此檔會出現在 iptables 在 /user/local/lib,iptables執行檔則是 /usr/local/sbin)
需要先編輯 Kernel 目錄底下的:
/net/ipv4/netfilter/ipt_layer7.c
底下,並搜尋到:
static int num_packets = ?? (並不是真的寫 ?? 只是我忘了它原本是多少了。)
這個 ?? 應該是原本的預設值,把它改為 8 再重新編譯 iptables 即可。

接著就可以開始定義規則了,
公司是使用 12M/1M ADSL線路,
因此我大略的分出 http, ftp, msn 傳檔以及P2P,加以限制。

以下是我定義的規則檔:

代碼:
#/bin/sh
#清除規則
echo ?#125;始執行QOS..................
echo 1.清除規則
tc qdisc del dev eth0 root 2>/dev/null
tc qdisc del dev eth1 root 2>/dev/null
tc qdisc del dev eth2 root 2>/dev/null
echo 2.定義最頂層
#定義上傳最頂層根部規則
tc qdisc add dev eth0 root handle 10: htb default 20
#定義下載最頂層根部規則
tc qdisc add dev eth1 root handle 20: htb default 20
#定義10:1總上傳頻寬
tc class add dev eth0 parent 10: classid 10:1 htb rate 1024kbps ceil 1024kbps
#定義10:1總下載頻寬
tc class add dev eth1 parent 20: classid 20:1 htb rate 12288kbps ceil 12288kbps
#這裡是各種分類
echo 3.?#125;始分類
#定義10:20 FTP 上傳
tc class add dev eth0 parent 10:1 classid 10:10 htb rate 384kbps ceil 512kbps prio 0
#定義20:20 FTP 下載
tc class add dev eth1 parent 20:1 classid 20:10 htb rate 1024kbps ceil 2048kbps prio 0
#定義10:10 網頁瀏覽上傳頻寬
tc class add dev eth0 parent 10:1 classid 10:20 htb rate 384kbps ceil 512kbps prio 1
#定義20:10 網頁瀏覽下載頻寬
tc class add dev eth1 parent 20:1 classid 20:20 htb rate 384kbps ceil 1024kbps prio 1
#定義20:40 MSN傳送檔案速度
tc class add dev eth0 parent 10:1 classid 10:30 htb rate 256kbps ceil 384kbps prio 2
#定義20:40 MSN接收檔案速度
tc class add dev eth1 parent 20:1 classid 20:30 htb rate 512kbps ceil 1024kbps prio 2
#定義10:30 P2P 上傳
tc class add dev eth0 parent 10:1 classid 10:40 htb rate 256kbps ceil 384kbps prio 3
#定義20:30 P2P 下載
tc class add dev eth1 parent 20:1 classid 20:40 htb rate 1024kbps ceil 2048kbps prio 3
echo 4.佇列宣告
#定義佇列規則
#給上傳
tc qdisc add dev eth0 parent 10:10 handle 101: pfifo
tc qdisc add dev eth0 parent 10:20 handle 102: pfifo
tc qdisc add dev eth0 parent 10:30 handle 103: pfifo
tc qdisc add dev eth0 parent 10:40 handle 104: pfifo
#給下載
tc qdisc add dev eth1 parent 20:10 handle 201: pfifo
tc qdisc add dev eth1 parent 20:20 handle 202: pfifo
tc qdisc add dev eth1 parent 20:30 handle 203: pfifo
tc qdisc add dev eth1 parent 20:40 handle 204: pfifo
echo 5.定義標籤
#過濾器
#?#93;定貼有"10"標籤的封?#93;歸類於"10:10"(以此類推)
#給上傳
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 1010 fw classid 10:10
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 1020 fw classid 10:20
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 1030 fw classid 10:30
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 1040 fw classid 10:40
#給下載
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 2010 fw classid 20:10
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 2020 fw classid 20:20
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 2030 fw classid 20:30
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 2040 fw classid 20:40
echo 6.清除 iptables mangle
#清除 mangle 內所有規則
/usr/local/sbin/iptables -F -t mangle

echo ...........................完成!!


程式執行結果:如果語法沒錯的話將會看到以下畫面:
(是我拿來 debug 用的啦)
開始執行QOS..................
1.清除規則
2.定義最頂層
3.開始分類
4.佇列宣告
5.定義標籤
6.清除 iptables mangle
...........................完成!!

接著開始執行 iptables 語法,貼上標籤之後就可實際運作!
代碼:
#layer7 QOS
#P2P
/usr/local/sbin/iptables -t mangle -A PREROUTING -m layer7 --l7proto edonkey -j MARK --set-mark 1040
/usr/local/sbin/iptables -t mangle -A PREROUTING -m layer7 --l7proto bittorrent -j MARK --set-mark 1040
/usr/local/sbin/iptables -t mangle -A POSTROUTING -m layer7 --l7proto edonkey -j MARK --set-mark 2040
/usr/local/sbin/iptables -t mangle -A POSTROUTING -m layer7 --l7proto bittorrent -j MARK --set-mark 2040
#上傳
/usr/local/sbin/iptables -t mangle -A PREROUTING -m layer7 --l7proto http -j MARK --set-mark 1010
/usr/local/sbin/iptables -t mangle -A PREROUTING -m layer7 --l7proto ftp -j MARK --set-mark 1020
/usr/local/sbin/iptables -t mangle -A PREROUTING -m layer7 --l7proto msn-filetransfer -j MARK --set-mark 1030
#下載
/usr/local/sbin/iptables -t mangle -I POSTROUTING -m layer7 --l7proto ftp -j MARK --set-mark 2010
/usr/local/sbin/iptables -t mangle -I POSTROUTING -m layer7 --l7proto http -j MARK --set-mark 2020
/usr/local/sbin/iptables -t mangle -I POSTROUTING -m layer7 --l7proto msn-filetransfer -j MARK --set-mark 2030


記住執行此語法之前要先安裝 l7-protocols 的 pack...這篇作者有提到可以最先做的。


PS: 若有人要拿小弟的當參考的話,注意一下P2P的部份,這部份我好像沒有成功,速度並沒被限制住...其他部份大都無問題....

以下是我的硬體環境

OS: CentOS 4.2 Kernel 2.6.14.2
CPU: Athlon XP 2500+
RAM: 1G
HD: 80G
eth0: ADSL 固定IP ,接到ATU-R
eth1: 客端網段,接到 switch
eth2: Server網段,接到 switch


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-12-06 17:59 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2004-06-11 14:26
文章: 46
johntino 寫:
如會有這些訊息是因為你的核心,有把L7的debug模式編進去~~~不想看到的話~~請把核心中debug的option拿掉~~~


請問可不可以把這訊息直接紀錄到檔案中而不是顯示於螢幕上?


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-12-09 11:51 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2004-06-11 14:26
文章: 46
之前的語法單位搞錯,小弟這兩天有空就試驗,終於成功的約束住 eMule 上傳

只要修改頻寬那部份即可

代碼:
#定義10:1總上傳頻寬
tc class add dev eth0 parent 10: classid 10:1 htb rate 100kbps ceil 100kbps
#定義10:1總下載頻寬
tc class add dev eth1 parent 20: classid 20:1 htb rate 1200kbps ceil 1200kbps
#這裡是各種分類
#定義10:10 FTP 上傳
tc class add dev eth0 parent 10:1 classid 10:10 htb rate 20kbps ceil 100kbps prio 0
#定義20:10 FTP 下載
tc class add dev eth1 parent 20:1 classid 20:10 htb rate 50kbps ceil 200kbps prio 0
#定義10:20 網頁瀏覽上傳頻寬
tc class add dev eth0 parent 10:1 classid 10:20 htb rate 50kbps ceil 100kbps prio 1
#定義20:20 網頁瀏覽下載頻寬
tc class add dev eth1 parent 20:1 classid 20:20 htb rate 150kbps ceil 200kbps prio 1
#定義20:30 MSN傳送檔案速度
tc class add dev eth0 parent 10:1 classid 10:30 htb rate 20kbps ceil 50kbps prio 2
#定義20:30 MSN接收檔案速度
tc class add dev eth1 parent 20:1 classid 20:30 htb rate 30kbps ceil 100kbps prio 2
#定義10:40 eMule 上傳
tc class add dev eth0 parent 10:1 classid 10:40 htb rate 12kbps ceil 25kbps prio 3
#定義20:40 eMule 下載
tc class add dev eth1 parent 20:1 classid 20:40 htb rate 20kbps ceil 200kbps prio 3
#定義10:50 BT 上傳
tc class add dev eth0 parent 10:1 classid 10:50 htb rate 12kbps ceil 25kbps prio 3
#定義20:50 BT 下載
tc class add dev eth1 parent 20:1 classid 20:50 htb rate 20kbps ceil 200kbps prio 3



規則也上下傳整合

代碼:
#定義佇列規則
#給上傳
tc qdisc add dev eth0 parent 10:10 handle 101: pfifo
tc qdisc add dev eth0 parent 10:20 handle 102: pfifo
tc qdisc add dev eth0 parent 10:30 handle 103: pfifo
tc qdisc add dev eth0 parent 10:40 handle 104: pfifo
tc qdisc add dev eth0 parent 10:50 handle 105: pfifo
#給下載
tc qdisc add dev eth1 parent 20:10 handle 101: pfifo
tc qdisc add dev eth1 parent 20:20 handle 102: pfifo
tc qdisc add dev eth1 parent 20:30 handle 103: pfifo
tc qdisc add dev eth1 parent 20:40 handle 104: pfifo
tc qdisc add dev eth1 parent 20:50 handle 105: pfifo
#過濾器
#]定貼有"10"標籤的封]歸類於"10:10"(以此類推)
#給上傳
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 10 fw classid 10:10
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 20 fw classid 10:20
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 30 fw classid 10:30
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 40 fw classid 10:40
tc filter add dev eth0 parent 10: protocol ip prio 100 handle 50 fw classid 10:50
#給下載
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 10 fw classid 20:10
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 20 fw classid 20:20
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 30 fw classid 20:30
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 40 fw classid 20:40
tc filter add dev eth1 parent 20: protocol ip prio 100 handle 50 fw classid 20:50


eMule 與BT 定為 40 與 50 的原因只是為了試試看效果,
兩個規則是一模一樣的,可以合成一個。


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2005-12-13 20:11 
離線
漸有心得的小鳥
漸有心得的小鳥

註冊時間: 2002-06-18 12:54
文章: 63
如果,我只想做限制每一個 connection 的頻寬要怎麼做

好像不用做到 L7 這麼複雜

_________________
http://www.kuolung.net


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2006-03-09 11:25 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2006-02-20 23:00
文章: 25
目前照這各位前輩的分享...編譯FC4中


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2006-03-28 17:06 
離線
初窺門徑的菜鳥
初窺門徑的菜鳥

註冊時間: 2005-11-15 16:32
文章: 51
請問大大....
有沒有在 ES4 上編譯 netfilter 的 patch 過. 參考了幾位大大的
文件; 不過在更新 kernel patch 時就不行了....
OS: Redhat ES4
Kernel: 2.6.9-5
netfilter-layer7-v2.1.tar.gz
l7-protocols-2006-03-13.tar.gz


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2007-12-31 11:55 
離線
初來乍到小菜鳥
初來乍到小菜鳥

註冊時間: 2007-12-31 11:21
文章: 1
非常感谢!


回頂端
 個人資料  
 
 文章主題 :
文章發表於 : 2008-08-05 12:57 
離線
初來乍到小菜鳥
初來乍到小菜鳥

註冊時間: 2005-09-16 13:12
文章: 4
請問各位大大
我裝好L7之後就是無法成功下規則
都出現 Segmentation fault
不知道這是啥問題
還請各位賜教解惑


回頂端
 個人資料  
 
顯示文章 :  排序  
發表新文章 回覆主題  [ 26 篇文章 ] 

所有顯示的時間為 UTC + 8 小時


誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客


不能 在這個版面發表主題
不能 在這個版面回覆主題
不能 在這個版面編輯您的文章
不能 在這個版面刪除您的文章

搜尋:
前往 :  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
正體中文語系由 竹貓星球 維護製作