參考文件:
Linux 2.4 Advanced Routing HOWTO
精彩討論:
有人在用cbq.init在做頻寬管理嗎?
實作參考:
專家級--阿忠哥
玩家級--VEGA
Download:
cbq.init-v0.7.1
開始實做:
當你把 cbq.init-v0.7.1 抓回來之後...所有的說明就已經在裡面...如果你想看完整版...直接參考該檔案即可...現在我們有 T1 ADSL 線路一條...
CODE:
+---------+ 192.168.0.1
T1_BACKBONE -----eth0-| linux |-eth1------*-[client]
+---------+
目標: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:
[cbq-0003.well_lan]
DEVICE=eth1
RATE=256Kbit
WEIGHT=25Kbit
PRIO=3
RULE=192.168.0.22
CODE:
[cbq-0102.well_adsl]
DEVICE=eth0,100Mbit,10Mbit
RATE=256Kbit
WEIGHT=25Kbit
PRIO=5
RULE=192.168.0.0/24
你會發現 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