Linux下簡單限制網卡頻寬的設定方法

來源:互聯網
上載者:User

   1、安裝iproute

  代碼如下:

  yum -y install iproute

  2、限制eth0網卡的頻寬為50kbit

  代碼如下:

  /sbin/tc qdisc add dev eth0 root tbf rate 50kbit latency 50ms burst 1000

  3、限制頻寬為50kbit後,在百兆區域網路中wget下載一個大檔案:

  代碼如下:

  [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,限制效果達到。

  4、解除eth0網卡的頻寬節流設定:

  代碼如下:

  /sbin/tc qdisc del dev eth0 root tbf

  5、對比:未作頻寬節流設定情況下,在百兆區域網路中wget下載一個大檔案:

  代碼如下:

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

  網友提問:限制頻寬為50kbit後, 為什麼下載速度達到457K/s?

  回複:Linux核心依靠粗糙的計時資訊進行頻寬固定。在一個較長的時間段內,可以維持很好的精度,但是在以秒為單位進行計量的時間段內,其結果非常不準確。

  所以,實際使用的頻寬需要以wget下載時速度為準,去調整tc的頻寬節流設定。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.