Centos 7 限制网速带宽(wondershaper+speedtest-cli) -云主机博士

Centos 7 限制网速带宽(wondershaper+speedtest-cli) -云主机博士 第1张

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

speedtest-cli 是一个用 Python 编写的轻量级的命令行工具,用於测试带宽。Python2.4+ 的环境下均可运行。它是基於 speedtest.net 的基础架构来测量网络的上/下行速率。

安装 wondershaper

yum install wondershaper

限制网速
限制eth0网卡下载速度为10Mbit/s,上传速度为15Mbit/s:

wondershaper eth0  10000 15000

取消限速:

wondershaper clear eth0

测试网速
安装 speedtest-cli:

wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py && chmod +x speedtest-cli

查看网速:

./speedtest-cli

返回结果:

Testing download speed.............................
Download: 0.79 Mbit/s
Testing upload speed...............................
Upload: 13.16 Mbit/s

参考链接

  • https://wuyanteng.github.io/2018/04/11/Linux网卡限速/

  • https://www.hjqjk.com/2018/Limit-the-bandwidth-in-Linux.html

  • https://www.convertworld.com/zh-hans/bandwidth/

  • https://github.com/sivel/speedtest-cli

  • 参数说明:

    -a :指定要限制的网卡名称或者接口名称
    -d :最大下载速率,单位:Kbps 。Kbps 即 Kb/s,p 是 peer 的意思。1KB/s=8Kb/s。1MB/s=1024KB/s。
    -u :最大上传速率,单位:Kbps 。
    -p :使用 /etc/conf.d/wondershaper.conf 的配置
    -c :清空所有规则,不再做任何限制
    -s :显示接口的当前状态
    使用 ip addr show 查看要限制带宽的网卡名称,老的机器可能没有这个命令,改用 ifconfig 查看。

宝塔服务器面板,一键全能部署及管理,送你3188元礼包,点我领取


iproyal.png
原文链接:,转发请注明来源!
「Centos 7 限制网速带宽(wondershaper+speedtest-cli) -云主机博士」评论列表

发表评论