linux 路由器 限速,Linux服务器限速WonderShaper使用方法 | 陌小九

Wondershaper是国外人开发的一款在Linux内核下基于TC工具的对整块网卡的限度工具。通过限制网络带宽,可以节省应用程序不必要的带宽消耗,包括软件包管理器(pacman、yum、apt)、web浏览器、torrent客户端、下载管理器等,并防止单个或多个用户滥用网络带宽。在本文当中,将会介绍 Wondershaper这一个实用的命令行程序,这是我认为限制Linux系统Internet或本地网络带宽的最简单、最快捷的方式之一。Wondershaper只能限制本地网络接口的传入和传出流量,而不能限制路由器或调制解调器的接口。换句话说,Wondershaper只会限制本地系统本身的网络带宽,而不会限制网络中的其它系统。因此Wondershaper主要用于限制本地系统中一个或多个网卡的带宽。

c12e68bdb511465bace6b3302b9c2ebe.png

安装Wondershaper

GitHub地址:https://github.com/magnific0/wondershaper

我们先安装依赖:

#Debian/Ubuntu系统

apt install -y make git

#CentOS系统

yum install make git -y

git clone https://github.com/magnific0/wondershaper.git

cd wondershaper

make install

安装完成后就可以使用了,命令如下:

USAGE: wondershaper [-hcs] [-a ] [-d ] [-u ]

OPTIONS:

-h Show this message

-a Set the adapter

-d Set maximum download rate (in Kbps) and/or

-u Set maximum upload rate (in Kbps)

-p Use presets in /etc/conf.d/wondershaper.conf

-c Clear the limits from adapter

-s Show the current status of adapter

-v Show the current version

-h 显示帮助

-a 设置适配器

-d 设置最大下载速率(以Kbps为单位)和/或

-u 设置最大上传速率(Kbps)

-p 使用/etc/conf.d/wondershaper.conf中的预设

-c 清除适配器的限制

-s 显示适配器的当前状态

下面是使用教程:

首先我们要搞清楚你用的哪个网卡,名字是什么?

查看网卡的命令有以下三个,我们推荐使用第一个

ifconfig

ip addr

route

找到你的网卡名,比如eth0,然后我们对他进行限速

#限制上传带宽为10M

wondershaper -a eth0 -u 10240

#限制下载带宽为10M

wondershaper -a eth0 -d 10240

#限制上传和上传均10M

wondershaper -a eth0 -d 10240 -u 10240

#清楚网卡限速规则

wondershaper -c -a eth0

设置后立即生效。然后因为默认是不跟随系统启动的,我们设置一下开机自启动。

一般使用rc.local来进行开机自启,但是Debian 9、Ubuntu 17+是没有rc.local文件的,使用这些系统的需要进行以下设置:

1、添加rc-local.service,以下为一整条命令,一起复制运行

cat > /etc/systemd/system/rc-local.service <

[Unit]

Description=/etc/rc.local

ConditionPathExists=/etc/rc.local

[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

StandardOutput=tty

RemainAfterExit=yes

SysVStartPriority=99

[Install]

WantedBy=multi-user.target

EOF

2、新建rc-local文件,以下为一整条命令,一起复制运行

cat > /etc/rc.local <

#!/bin/sh -e

#

# rc.local

#

# This script is executed at the end of each multiuser runlevel.

# Make sure that the script will "exit 0" on success or any other

# value on error.

#

# In order to enable or disable this script just change the execution

# bits.

#

# By default this script does nothing.

EOF

3、添加权限并设置开机自启

chmod +x /etc/rc.local

systemctl start rc-local

systemctl enable rc-local

上面就设置好了Debian 9、Ubuntu 17+的rc.local文件。

下面我们将启动命令加入rc.local文件,使用命令:

#CentOS 7系统

echo "wondershaper -a eth0 -d 10240 -u 10240" >> /etc/rc.d/rc.local

chmod +x /etc/rc.d/rc.local

#CentOS 6、Debian、Ubuntu系统

echo "wondershaper -a eth0 -d 10240 -u 10240" >> /etc/rc.local

chmod +x /etc/rc.local

这里限速命令自行修改。

使用Systemd

由于安装的时候,Systemd配置文件也给你了,所以就方便使用了,不过该方法只适用于CentOS 7、Debian 8+、Ubuntu 16+等。

由于启动时,默认调用的配置文件为/etc/conf.d/wondershaper.conf,所以先编辑该文件:

nano /etc/conf.d/wondershaper.conf

也可以使用宝塔来编辑。

[wondershaper]

# Adapter

#

IFACE="eth0"

# Download rate in Kbps

#

DSPEED="10240"

# Upload rate in Kbps

#

USPEED="10240"

参数依次为网卡、下载、上传限制,修改好了后,使用Ctrl+x、y保存退出。

再启动程序并开机自启:

systemctl start wondershaper

systemctl enable wondershaper

Wondershaper按照以上设置可以很好的限速,有需要的 小伙伴可以试试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值