小白网卡带宽限速神器:wondershaper

介绍

WonderShaper是一个用于对特定网卡进行带宽限速的脚本,它封装了linux的tc命令,但是使用起来更加简单和方便,如果你对限速要求不多,可以用wondershaper满足你大部分需求。

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

 

使用场景

像有些做流量控制的软件都会涉及到此类限速场景,比如测试一些离线上传功能,在网卡带宽较小的情况下,是否能够优雅处理完所有离线数据上报。

弱网测试,比如手机连接linux机器的共享网络,可以通过这种方式限速做弱网测试

 

安装

Ubuntu:

sudo apt-get update
sudo apt install -y wondersharper

Centos

yum install epel-release -y
sudo yum install -y wondersharper

使用二进制

1)下载wondershaper工程

git clone https://github.com/magnific0/wondershaper.git
cd wondershaper 
#直接运行wondershaper
./wondershaper

2)全局安装wondershaper(可选)

cd wondershaper
sudo make install

帮助

输入:./wondershaper -h

USAGE: ./wondershaper [-hcs] [-a <adapter>] [-d <rate>] [-u <rate>]
 
Limit the bandwidth of an adapter
 
OPTIONS:
-h Show this message                                 //显示帮助信息
-a <adapter> Set the adapter                         //指定网卡接口,通过ifconifg或者ip show addr查看:比如eth0
-d <rate> Set maximum download rate (in Kbps) and/or //限制下载的速度
-u <rate> Set maximum upload rate (in Kbps)          //限制上传的速度
-p Use presets in "/etc/systemd/wondershaper.conf"
-c Clear the limits from adapter                     //清除对应网卡接口的规则
-s Show the current status of adapter                //显示当前网卡状态
-v Show the current version                          //显示版本信息
 
Configure HIPRIODST in "/etc/systemd/wondershaper.conf" for hosts
requiring high priority i.e. in case ssh uses dport 443.
 
MODES:
wondershaper -a <adapter> -d <rate> -u <rate>
wondershaper -c -a <adapter>
wondershaper -s -a <adapter>
 
EXAMPLES: //针对以上示例给出的example
wondershaper -a eth0 -d 1024 -u 512    //限制eth0上行速度512kbps,下行速度1024kbps
wondershaper -a eth0 -u 512            //仅限制eth0上行速度512kbps
wondershaper -c -a eth0                //清除为eth0设定的wondershaper的相关规则

例子

1.限制eth0的上行带宽为100Mbps,下行带宽为100Mbps

wondershaper -a eth1 -d 94000 -u 94000

 

2.限制eth0的上行带宽为100Mbps

wondershaper -a eth1 -u 94000

 

3.清理eth0上的带宽限制规则

wondershaper -c -a eth0

 

4.查看eth0当前的状态

wondershaper -s -a eth0

 

5.使用systemd管理wondershaper

1) 安装到系统目录:sudo make install

如图所示,wondershaper一键被添加到systemd进行管理了。

2)相关操作

#启动限流操作
service wondershaper start
#停止限流操作
service wondershaper stop

3)设置相关规则

sudo vim /etc/systemd/wondershaper.conf,修改如下内容

[wondershaper]
 
# Adapter
IFACE="eth0" //相当于命令中的-a对应值设置
 
# Download rate in Kbps
DSPEED="2048" //相当于命令中的-d对应值设置
 
# Upload rate in Kbps
USPEED="512" //相当于命令中的-u对应值设置

FAQ

执行命令报错:Operation not permitted 

命令加上sudo,提升权限

传送门:2021最新测试资料与大厂招聘合集

博主:测试生财(一个不为996而996的测开码农)

座右铭:专注测试开发与自动化运维,努力读书思考写作,为内卷的人生奠定财务自由。

内容范畴:技术提升,职场杂谈,事业发展,阅读写作,投资理财,健康人生。

csdn:https://blog.csdn.net/ccgshigao

博客园:https://www.cnblogs.com/qa-freeroad/

51cto:https://blog.51cto.com/14900374

微信公众号:测试生财(定期分享独家内容和资源)

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

公众号-测试生财

点赞和关注比打赏更重要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值