adj 2007-11-29 17:53
利用 cbq.init 來幫你做頻寬控管
Linux 包含複雜的頻寬管理系統 TC (流量控制,Traffic Control)。該系統支持分類、優先、共享和輸入、輸出流量限制等。這套系統可以與專用的帶寬管理系統相媲美。在看過相關的頻寬控管文章後...個人覺得 CBQ(Class-Based Queueing) 難度還是滿高的...要控管的很複雜的話...需要多花點時間才能做的出來...不過目前我只想要用 ADSL 來限制區網內的電腦...讓內部電腦能夠受到 NAT 的頻寬限制...不至於猛Download ...佔用他人的頻寬..而沒有他的辦法ㄋㄟ...因此在這邊不需要用到太複雜的功能...只需要幾個步驟及可..
參考文件:
[url=http://cldp.hklpg.org/Adv-Routing-HOWTO-9.html]Linux 2.4 Advanced Routing HOWTO[/url]
精彩討論:
[url=http://phorum.study-area.org/viewtopic.php?t=10356&highlight=cbq]有人在用cbq.init在做頻寬管理嗎?[/url]
實作參考:
[url=http://www.study-area.org/tips/cbq.htm]專家級--阿忠哥[/url]
[url=http://www.study-area.org/tips/cbq_init/cbq_init.htm]玩家級--VEGA[/url]
Download:
[url=https://sourceforge.net/project/showfiles.php?group_id=42529&release_id=108424]cbq.init-v0.7.1[/url]
開始實做:
當你把 cbq.init-v0.7.1 抓回來之後...所有的說明就已經在裡面...如果你想看完整版...直接參考該檔案即可...現在我們有 T1 ADSL 線路一條...
[code] +---------+ 192.168.0.1
T1_BACKBONE -----eth0-| linux |-eth1------*-[client]
+---------+[/code]
目標:
1.內部上網 client(192.168.0.0/24) 保有 800Kbit(100Kbps) 的上網品質
2.一但發現有人在長時間 Download 時...能夠將其頻寬馬上限制...這點很好用...雖然是被動的...但是很有趣...因為他會連上網都變的很慢...就不在 800Kbit 的範圍內了...
3.上傳部份限制在 256Kbit(32Kbps)
CBQ所有的組態檔案,預設儲存路徑在/etc/sysconfig/cbq裡邊,檔案格式規定以cbq-[編號1][編號2].class_name
組態檔案的編號1與編號2為兩組16進位數值,從0002至FFFF。
設定檔參考(底下是分成三個檔案):
[code][cbq-0002.well_lan]
DEVICE=eth1,100Mbit,10Mbit
RATE=800Kbit
WEIGHT=80Kbit
PRIO=5
RULE=192.168.0.0/24:80[/code]
[code][cbq-0003.well_lan]
DEVICE=eth1
RATE=256Kbit
WEIGHT=25Kbit
PRIO=3
RULE=192.168.0.22[/code]
[code][cbq-0102.well_adsl]
DEVICE=eth0,100Mbit,10Mbit
RATE=256Kbit
WEIGHT=25Kbit
PRIO=5
RULE=192.168.0.0/24[/code]
你會發現 cbq-0003.well_adsl 它的優先權比較高(PRIO=3)...假設是 192.168.0.22 這個IP流量異常...你把它限制住...到時就會有人唉唉叫啦...
參數 Parameter 說明:
DEVICE=<ifname>,<bandwidth>[,<weight>] mandatory
DEVICE=eth0,10Mbit,1Mbit
<ifname> is the name of the interface you want to control
traffic on, e.g. eth0
<bandwidth> is the physical bandwidth of the device, e.g. for
ethernet 10Mbit or 100Mbit, for arcnet 2Mbit
<weight> is tuning parameter that should be proportional to
<bandwidth>. As a rule of thumb: <weight> = <bandwidth> / 10
When you have more classes on one interface, it is enough to specify
<bandwidth> [and <weight>] only once, therefore in other files you only
need to set DEVICE=<ifname>.
Class parameters
RATE=<speed> mandatory
RATE=5Mbit
Bandwidth allocated to the class. Traffic going through the class is shaped to conform to specified rate. You can use Kbit, Mbit or bps,
Kbps and Mbps as suffices. If you don't specify any unit, bits/sec
are used. Also note that "bps" means "bytes per second", not bits.
WEIGHT=<speed> mandatory
WEIGHT=500Kbit
Tuning parameter that should be proportional to RATE. As a rule of thumb, use WEIGHT ~= RATE / 10.
PRIO=<1-8> optional, default 5
PRIO=5
Priority of class traffic. The higher the number, the lesser
the priority. Priority of 5 is just fine.
Filter parameters
RULE=[[saddr[/prefix]][:port[/mask]],][daddr[/prefix]][:port[/mask]]
These parameters make up "u32" filter rules that select traffic for
each of the classes. You can use multiple RULE fields per config.
The optional port mask should only be used by advanced users who
understand how the u32 filter works.
Some examples:
RULE=10.1.1.0/24:80
selects traffic going to port 80 in network 10.1.1.0
RULE=10.2.2.5
selects traffic going to any port on single host 10.2.2.5
RULE=10.2.2.5:20/0xfffe
selects traffic going to ports 20 and 21 on host 10.2.2.5
RULE=:25,10.2.2.128/26:5000
selects traffic going from anywhere on port 50 to
port 5000 in network 10.2.2.128
RULE=10.5.5.5:80,
selects traffic going from port 80 of single host 10.5.5.5