mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
PRF:20180906 How To Limit Network Bandwidth In Linux Using Wondershaper.md
@HankChow
This commit is contained in:
parent
7b5b07f7e4
commit
eb05f1d1a9
@ -11,101 +11,84 @@
|
||||
|
||||
### 在 Linux 中使用 Wondershaper 限制网络带宽
|
||||
|
||||
`wondershaper` 是用于显示系统网卡网络带宽的简单脚本。它使用了 `iproute` 和 `tc` 命令,但大大简化了操作过程。
|
||||
`wondershaper` 是用于显示系统网卡网络带宽的简单脚本。它使用了 iproute 的 `tc` 命令,但大大简化了操作过程。
|
||||
|
||||
**安装 Wondershaper**
|
||||
#### 安装 Wondershaper
|
||||
|
||||
使用 `git clone` 克隆 Wondershaper 的版本库就可以安装最新版本:
|
||||
|
||||
```
|
||||
$ git clone https://github.com/magnific0/wondershaper.git
|
||||
|
||||
```
|
||||
|
||||
按照以下命令进入 `wondershaper` 目录并安装:
|
||||
|
||||
```
|
||||
$ cd wondershaper
|
||||
|
||||
$ sudo make install
|
||||
|
||||
```
|
||||
|
||||
然后执行以下命令,可以让 `wondershaper` 在每次系统启动时都自动开始服务:
|
||||
|
||||
```
|
||||
$ sudo systemctl enable wondershaper.service
|
||||
|
||||
$ sudo systemctl start wondershaper.service
|
||||
|
||||
```
|
||||
|
||||
如果你不强求安装最新版本,也可以使用软件包管理器(官方和非官方均可)来进行安装。
|
||||
|
||||
`wondershaper` 在 [Arch 用户软件仓库][1](Arch User Repository, AUR)中可用,所以可以使用类似 [`yay`][2] 这些 AUR 辅助软件在基于 Arch 的系统中安装 `wondershaper` 。
|
||||
`wondershaper` 在 [Arch 用户软件仓库][1](Arch User Repository,AUR)中可用,所以可以使用类似 [yay][2] 这些 AUR 辅助软件在基于 Arch 的系统中安装 `wondershaper` 。
|
||||
|
||||
```
|
||||
$ yay -S wondershaper-git
|
||||
|
||||
```
|
||||
|
||||
对于Debian、Ubuntu 和 Linux Mint 可以使用以下命令安装:
|
||||
对于 Debian、Ubuntu 和 Linux Mint 可以使用以下命令安装:
|
||||
|
||||
```
|
||||
$ sudo apt-get install wondershaper
|
||||
|
||||
```
|
||||
|
||||
对于 Fedora 可以使用以下命令安装:
|
||||
|
||||
```
|
||||
$ sudo dnf install wondershaper
|
||||
|
||||
```
|
||||
|
||||
对于 RHEL、CentOS,只需要启用 EPEL 仓库,就可以使用以下命令安装:
|
||||
|
||||
```
|
||||
$ sudo yum install epel-release
|
||||
|
||||
$ sudo yum install wondershaper
|
||||
|
||||
```
|
||||
|
||||
在每次系统启动时都自动启动 `wondershaper` 服务。
|
||||
|
||||
```
|
||||
$ sudo systemctl enable wondershaper.service
|
||||
|
||||
$ sudo systemctl start wondershaper.service
|
||||
|
||||
```
|
||||
|
||||
**用法**
|
||||
#### 用法
|
||||
|
||||
首先需要找到网络接口的名称,通过以下几个命令都可以查询到网卡的详细信息:
|
||||
|
||||
```
|
||||
$ ip addr
|
||||
|
||||
$ route
|
||||
|
||||
$ ifconfig
|
||||
|
||||
```
|
||||
|
||||
在确定网卡名称以后,就可以按照以下的命令限制网络带宽:
|
||||
|
||||
```
|
||||
$ sudo wondershaper -a <adapter> -d <rate> -u <rate>
|
||||
|
||||
```
|
||||
|
||||
例如,如果网卡名称是 `enp0s8`,并且需要把上行、下行速率分别限制为 1024 Kbps 和 512 Kbps,就可以执行以下命令:
|
||||
|
||||
```
|
||||
$ sudo wondershaper -a enp0s8 -d 1024 -u 512
|
||||
|
||||
```
|
||||
|
||||
其中参数的含义是:
|
||||
@ -114,20 +97,16 @@ $ sudo wondershaper -a enp0s8 -d 1024 -u 512
|
||||
* `-d`:下行带宽
|
||||
* `-u`:上行带宽
|
||||
|
||||
|
||||
|
||||
如果要对网卡解除网络带宽的限制,只需要执行:
|
||||
|
||||
```
|
||||
$ sudo wondershaper -c -a enp0s8
|
||||
|
||||
```
|
||||
|
||||
或者:
|
||||
|
||||
```
|
||||
$ sudo wondershaper -c enp0s8
|
||||
|
||||
```
|
||||
|
||||
如果系统中有多个网卡,为确保稳妥,需要按照上面的方法手动设置每个网卡的上行、下行速率。
|
||||
@ -149,13 +128,14 @@ DSPEED="2048"
|
||||
# Upload rate in Kbps
|
||||
#
|
||||
USPEED="512"
|
||||
|
||||
```
|
||||
|
||||
Wondershaper 使用前:
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/09/wondershaper-1.png)
|
||||
|
||||
Wondershaper 使用后:
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/09/wondershaper-2.png)
|
||||
|
||||
可以看到,使用 Wondershaper 限制网络带宽之后,下行速率与限制之前相比已经大幅下降。
|
||||
@ -164,21 +144,16 @@ Wondershaper 使用后:
|
||||
|
||||
```
|
||||
$ wondershaper -h
|
||||
|
||||
```
|
||||
|
||||
也可以查看 Wondershaper 的用户手册:
|
||||
|
||||
```
|
||||
$ man wondershaper
|
||||
|
||||
```
|
||||
|
||||
As far as tested, Wondershaper worked just fine as described above. Give it a try and let us know what do you think about this utility.
|
||||
根据测试,Wondershaper 按照上面的方式可以有很好的效果。你可以试用一下,然后发表你的看法。
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-limit-network-bandwidth-in-linux-using-wondershaper/
|
||||
@ -186,7 +161,7 @@ via: https://www.ostechnix.com/how-to-limit-network-bandwidth-in-linux-using-won
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[HankChow](https://github.com/HankChow)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user