手动限制VPS主机网络带宽的脚本:WonderShaper,避免触发限速规则

有些主机商家的带宽限速规则比较严格, 比如多少分钟内,占用过高,比如超过多少Mbps的话就限速,这个时候可以自己手动限速, 可以避免触发限速规则。WonderShaper 是一个专门用于手动限制 VPS 网络带宽的脚本,用于对特定网卡进行带宽限速,封装 linux 的 tc 命令,使用起来更加简单和方便。

项目地址:https://github.com/magnific0/wondershaper

安装 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主机网络带宽的脚本:WonderShaper,避免触发限速规则

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏