使用 wondershaper 在 Linux 中限制网络带宽使用

wondershaper 实际上是一个 shell 脚本,它使用 tc 来定义流量调整命令,使用 QoS 来处理特定的网络接口。外发流量通过放在不同优先级的队列中,达到限制传出流量速率的目的;而传入流量通过丢包的方式来达到速率限制的目的。

事实上, wondershaper 的既定目标不仅仅是对一个接口增加其带宽上限;当批量下载或上传正在进行时,wondershaper 还试图去保持互动性会话如 SSH 的低延迟。同样的,它还会控制批量上传(例如, Dropbox 的同步)不会使得下载“窒息”,反之亦然。

在 Ubuntu Debian 及其衍生发行版中安装 wondershaper:

sudo apt-get install wondershaper

在 Fdora 或 CentOS/RHEL (带有 EPEL 软件仓库) 中安装 wondershaper:

sudo yum install wondershaper

wondershaper 的基本使用如下:

sudo wondershaper <interface> <download-rate> <upload-rate>

举个例子, 将 eth0 的最大下载/上传带宽分别设定为 1000Kbit/s 和 500Kbit/s:

sudo wondershaper eth0 1000 500

你也可以通过运行下面的命令将速率限制进行消除:

sudo wondershaper clear eth0

假如你对 wondershaper 的运行原理感兴趣,你可以阅读其 shell 脚本源文件(/sbin/wondershaper)。

 

PS:

http://www.linuxidc.com/Linux/2015-03/115538.htm

posted @ 2016-01-07 23:25  phpdragon  阅读(5578)  评论(0编辑  收藏  举报