使用二进制

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对应值设置
Last modification:June 4, 2024
如果觉得我的文章对你有用,请随意赞赏