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

介绍

WonderShaper是一个用于对特定网卡进行带宽限速的脚本,它封装了linux的tc命令,可是使用起来更加简单和方便,若是你对限速要求很少,能够用wondershaper知足你大部分需求。linux

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

 

使用场景

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

弱网测试,好比手机链接linux机器的共享网络,能够经过这种方式限速作弱网测试vim

 

安装

Ubuntu:微信

sudo apt-get updatesudo apt install -y wondersharper


Centos网络

yum install epel-release -ysudo yum install -y wondersharper

使用二进制运维

1)下载wondershaper工程ssh

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

2)全局安装wondershaper(可选)ide

cd wondershapersudo 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,下行速度1024kbpswondershaper -a eth0 -u 512            //仅限制eth0上行速度512kbpswondershaper -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进行管理了。

 image.png


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,提高权限

 

快送门:各类学习资料与大厂招聘

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

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

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

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

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

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

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

相关文章
相关标签/搜索