WonderShaper – A Tool to Limit Network Bandwidth in Linux

[‘

n

Wondershaper is a small bash script that enables you to limit the network bandwidth in Linux. It employs the tc command line program as the backend for configuring traffic control. It is a handy tool for controlling bandwidth on a Linux server.

n

It allows you to set the maximum download rate and/or maximum upload rate. In addition, it also allows you to clear the limits that you have set and can display the current status of an interface from the command line. Instead of using the CLI options, you can run it persistently as a service under systemd.

n

In this article, we will show how to install and use wondershaper for limiting network bandwidth on Linux systems.

n

How to Install Wondershaper in Linux Systems

n

First, start by installing wondershaper using your Linux distribution package manager from the default repertoires as shown.

n

$ sudo apt install wondershaper  [On Debian/Ubuntu]rn$ sudo yum install wondershaper  [On CentOS/RHEL]rn$ sudo dnf install wondershaper  [On Fedora 22+]rn

n

Alternatively, to pull and install the latest updates, you need to clone the GitHub repository of wondershaper to your system, move into the local repository and install it using the following commands. Note that you should have the git command line tool installed:

n

$ cd binrn$ git clone https://github.com/magnific0/wondershaper.gitrn$ cd wondershaperrn$ sudo make installrn

n

Before you start using wondershaper, you should first of all check all network interfaces attached to your machine using ifconfig or ip command.

n

This will help you know the interface on which you want to shape bandwidth usage, for example the wireless interface wlp1s0 which is active.

n

$ ifconfig rnORrn$ ip addrrn

n

Check Network Interfaces in Linux
Check Network Interfaces in Linux

n

How to Use Wondershaper to Limit Network Bandwidth in Linux

n

To define the maximum download rate in Kbps for an interface, run the following command using the option -a (defines interface) and -d (defines Kbps) i.e the download rate will be set to 4Mbps.

n

$ wondershaper -a wlp1s0 -d 4048rn

n

To set the maximum upload rate in Kbps for an interface, use the -u option as follows.

n

$ wondershaper -a wlp1s0 -u 1048rn

n

You can also set download and upload at once with a single command, for instance.

n

$ wondershaper -a wlp1s0 -d 4048 -u 1048rn

n

The -s option allows you to view the current status of an interface.

n

$ wondershaper -sa wlp1s0 rn

n

Check Network Interface Status
Check Network Interface Status

n

You can also use iPerf – network throughput tool to test the bandwidth reduction by wondershaper, for example.

n

You can clear the download or upload limits you have set for an interface using the -c flag.

n

$ wondershaper -ca wlp1s0rn

n

It is also possible to run wondershaper as a service, where you define the parameters for shaping bandwidth in a config file. This enables wondershaper to start at boot time and limit bandwidth usage at all times, when the system is on, as explained in the next section.

n

How to Run Wondershaper Persistently Under Systemd

n

Under this mode, you need to set the interface, upload and download rates in the wondershaper configuration file located at /etc/conf.d/wondershaper. You can open this file for editing using your favorite CLI editor as shown.

n

$ sudo vim /etc/conf.d/wondershaper rn

n

Define the necessary parameters as follows.

n

[wondershaper]rn# AdapterrnIFACE="wlp1s0"rnrn# Download rate in KbpsrnDSPEED="4048"rnrn# Upload rate in KbpsrnUSPEED="512"rn

n

Save the file and close it.

n

Next, start the wondershaper service for the mean time, enable it to auto-start at system boot and view its status, using the systemctl command.

n

$ sudo systemctl start wondershaperrn$ sudo systemctl enable wondershaperrn$ sudo systemctl status wondershaperrn

n

In case you alter the values of the parameters in the config file, you need to restart the wonderservice for the changes to be effected.

n

$ sudo systemctl restart wondershaperrn

n

To stop the wondershaper service, use the following command.

n

$ sudo systemctl stop wondershaperrn

n

For more help, see the Wondershaper Github repository: https://github.com/magnific0/wondershaper

n

Wondershaper is a traffic shaper for limiting network bandwidth on Linux systems. Try it out and share your thoughts with us via the feedback form below. If you know of any similar tools out there, you can as well mention to us in the comments – we will be grateful.

n

‘]