VPS 限制网速带宽 Linux网卡限速

vps.dance 2022-02-07 2022-02-13 1690℃

Wondershaper介绍: WonderShaper 是一个限制网络带宽的脚本, 可用于对特定网卡进行带宽限速, 它封装了linux的tc命令, 但是使用起来更加简单和方便.

安装 wondershaper

curl -Lo /usr/sbin/wondershaper https://raw.githubusercontent.com/magnific0/wondershaper/master/wondershaper;
chmod +x /usr/sbin/wondershaper;

查询网卡

ifconfig # 大多数为 eth0

对网卡设置限速

wondershaper -a eth0 -d 5000  -u 2000 # 限制 下载 5Mbps, 上传 2Mbps
# wondershaper -a eth0 -d 90000 -u 90000 # 限制 下载  90Mbps, 上传 90Mbps

-a 网卡名(这里设了 eth0)
-d 下载速度 (单位为 Kbps)
-u 上传速度 (单位为 Kbps)
速度单位为 Kbps(Kbit/s) (100000 Kbps = 100Mbps = 12.5 MB/s)

取消网卡限速

wondershaper -a eth0 -c # eth0 为网卡名

查看状态

wondershaper -a eth0 -s # eth0 为网卡名

speedtest 测试网速

安装speedtest 的教程

speedtest # 根据就近节点, 测试限速效果

防止重启机器, 限速失效

  • 安装服务:

    curl -Lo /etc/systemd/system/wondershaper.service https://raw.githubusercontent.com/magnific0/wondershaper/master/wondershaper.service;
    systemctl daemon-reload;
  • 创建配置文件

    curl -Lo /etc/systemd/wondershaper.conf https://raw.githubusercontent.com/magnific0/wondershaper/master/wondershaper.conf;
    # 编辑 配置文件
    vim /etc/systemd/wondershaper.conf
    # 根据需要, 修改 IFACE, DSPEED, USPEED 的值即可
  • 启动服务

    systemctl enable --now wondershaper.service

限速的用途

某些VPS商家的带宽限速规则较严格, 比如多少分钟内, 占用过高(比如超过多少Mbps) 就限速.
自己手动限速, 可以避免 触发限速规则.

标签: VPS, Speedtest, 限速

非特殊说明, 所有文章均为原创.