wondershaper 可以限制 linux 服务器网卡级别的带宽
速率在线换算:http://www.zhongguosou.com/computer_question_tools/data_rate_caculator.html
下载 wondershaper
cd /usr/local/
git clone https://github.com/magnific0/wondershaper.git
cd wondershaper
wondershaper 使用

// 单位是 Kbps
./wondershaper -a 网口名称 -u 上传速度 -d 下载速度
// 限制 eth0 网口上传下载为 150 Kbps
./wondershaper -a eno5 -u 921600 -d 921600
// 可以看到多了一个 ifb0 网口
# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:16:3e:0e:48:a7 brd ff:ff:ff:ff:ff:ff
inet 10.3.200.99/22 brd 10.3.203.255 scope global dynamic eth0
valid_lft 304404587sec preferred_lft 304404587sec
3: ifb0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 32
link/ether 96:3a:32:74:1e:01 brd ff:ff:ff:ff:ff:ff
// 查看限速状态
./wondershaper -a eth0 -s
//取消限速
./wondershaper -a eth0 -c
作者:awker
链接:https://www.jianshu.com/p/99b05fa5ad0a
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
获得奇迹塑造者
建议克隆 Wondershaper 的 GitHub 存储库,以便您可以随时提取新的更新(如果可用)。打开一个新终端并使用克隆存储库
git clone https://github.com/magnific0/wondershaper.git
这将在您当前文件夹中的一个名为 wondershaper 的新文件夹中克隆 Wondershaper。现在使用
cd wondershaper
使用奇迹塑造者
您可以在不安装的情况下运行 wondershaper(作为具有足够权限的任何用户),此时停止按照说明操作。通过键入显示 wondershaper 使用说明
./wondershaper -h
该程序详细介绍了有关如何使用 Wondershaper 的所有可用选项。接下来是选择一个你想要塑造的界面。您可以通过键入查看所有可用的接口
ip addr show
请注意,在旧系统上,此命令可能不可用。在这种情况下,您应该运行ifconfig
。
确定要塑造的网络接口。名称因系统而异。
在以下示例中,无线接口被限制为4Mbps 的上传和 8Mbps 的下载。
./wondershaper -a wlp4s0 -u 4096 -d 8192
如果您收到消息,告诉您RTNETLINK answers: Operation not permitted
您的用户帐户没有足够的权限。在这种情况下尝试:
sudo ./wondershaper -a wlp4s0 -u 4096 -d 8192
系统安装(可选)
为便于安装而提供的 makefile 文件。Wondershaper 的默认位置在/usr/bin
. 如果要安装到系统中,可以运行:
sudo make install
您可以通过输入以下内容来验证是否正确安装了 Wondershaper:
which wondershaper
这应该返回/usr/bin/wondershaper
。您可以按照“使用 Wondershaper”部分中解释的相同说明进行操作,但现在您可以通过删除./
每个命令开头的 来运行系统版本,而不是运行程序的本地版本。例如要再次显示帮助说明,请运行:
wondershaper -h
持续使用 Wondershaper(可选)
不必像前面显示的那样使用命令行选项来设置速率和界面,而是需要在wondershaper.conf
配置文件中设置这些参数。您可以使用您喜欢的文本编辑器(下面示例中的 vim)编辑此文件,如下所示:
sudo vim /etc/systemd/wondershaper.conf
为了确保 Wondershaper 在重新启动时重新激活,提供了 systemd 服务文件。首先使用以下命令将 Wondershaper 启用为 systemd 服务:
sudo systemctl enable --now wondershaper.service
这样,wondershaper 会在重新启动时使用您的设置激活。
用法
wondershaper [-hcs] [-a <adapter>] [-d <rate>] [-u <rate>]
允许使用以下命令行选项:
-h
显示帮助-a <adapter>
设置适配器-d <rate>
设置最大下载速率(Kbps)和/或-u <rate>
设置最大上传速率(Kbps)-p
使用 /etc/systemd/wondershaper.conf 中的预设-f <file>
使用替代预设文件-c
清除适配器的限制-s
显示适配器的当前状态
不同的模式是:
wondershaper -a <adapter> -d <rate> -u <rate>
wondershaper -c -a <adapter>
wondershaper -s -a <adapter>
一些例子:
wondershaper -a eth0 -d 1024 -u 512
wondershaper -a eth1 -d 94000 -u 94000 # could be used on a 100Mbps link
wondershaper -a eth1 -u 94000 # only limit upload
wondershaper -c -a eth0
wondershaper -p -f foo.conf
Comments NOTHING