VPS 从网卡层面设置限速,以应对商家黑洞问题
Wondershaper介绍: WonderShaper 是一个限制网络带宽的脚本, 可用于对特定网卡进行带宽限速, 它封装了linux的tc命令, 但是使用起来更加简单和方便.
该教程仅在Debian11系统上测试通过,其它系统未经测试。
安装
安装 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 为网卡名
设置开机自启
安装服务:
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) 就限速或者黑洞.
自己手动限速, 可以避免 触发限速规则.
版权声明:
作者:Geeker
链接:https://www.vpsgeeker.com/2024/03/01/xiansu-heidong.html
文章版权归作者所有,未经允许请勿转载。
THE END