1、安裝iproute
yum -y install iproute
2、限制eth0網(wǎng)卡的帶寬為50kbit:
/sbin/tc qdisc add dev eth0 root tbf rate 50kbit latency 50ms burst 1000
3、限制帶寬為50kbit后,在百兆局域網(wǎng)中wget下載一個(gè)大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip
--19:40:27-- http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'
37% [=======> ] 8,994,816 457K/s eta 27s
下載速度為457K/s,限制效果達(dá)到。
4、解除eth0網(wǎng)卡的帶寬限制:
/sbin/tc qdisc del dev eth0 root tbf
5、對(duì)比:未作帶寬限制情況下,在百兆局域網(wǎng)中wget下載一個(gè)大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip
--19:44:33-- http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'
100%[==========>] 23,862,312 6.14M/s in 3.7s
19:44:36 (6.16 MB/s) - `test.zip' saved [23862312/23862312]
下載速度為6.16MB/s。
網(wǎng)友提問(wèn):限制帶寬為50kbit后, 為什么下載速度達(dá)到457K/s?
回復(fù):Linux內(nèi)核依靠粗糙的計(jì)時(shí)信息進(jìn)行帶寬固定。在一個(gè)較長(zhǎng)的時(shí)間段內(nèi),可以維持很好的精度,但是在以秒為單位進(jìn)行計(jì)量的時(shí)間段內(nèi),其結(jié)果非常不準(zhǔn)確。
所以,實(shí)際使用的帶寬需要以wget下載時(shí)速度為準(zhǔn),去調(diào)整tc的帶寬限制。
本文轉(zhuǎn)自:http://blog.s135.com/post/380/