WonderShaper – A Tool to Limit Network Bandwidth in Linux

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.

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.

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

How to Install Wondershaper in Linux Systems

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

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

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:

$ cd bin
$ git clone https://github.com/magnific0/wondershaper.git
$ cd wondershaper
$ sudo make install

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

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

$ ifconfig 
OR
$ ip addr
Check Network Interfaces in Linux

Check Network Interfaces in Linux

How to Use Wondershaper to Limit Network Bandwidth in Linux

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.

$ wondershaper -a wlp1s0 -d 4048

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

$ wondershaper -a wlp1s0 -u 1048

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

$ wondershaper -a wlp1s0 -d 4048 -u 1048

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

$ wondershaper -sa wlp1s0 
Check Network Interface Status

Check Network Interface Status

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

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

$ wondershaper -ca wlp1s0

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.

How to Run Wondershaper Persistently Under Systemd

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.

$ sudo vim /etc/conf.d/wondershaper 

Define the necessary parameters as follows.

[wondershaper]
# Adapter
IFACE="wlp1s0"

# Download rate in Kbps
DSPEED="4048"

# Upload rate in Kbps
USPEED="512"

Save the file and close it.

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.

$ sudo systemctl start wondershaper
$ sudo systemctl enable wondershaper
$ sudo systemctl status wondershaper

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.

$ sudo systemctl restart wondershaper

To stop the wondershaper service, use the following command.

$ sudo systemctl stop wondershaper

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

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.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

5 Responses

  1. Morgan Collett says:

    On Ubuntu 18.04 the syntax is completely different:

    wondershaper [interface] [downlink] [uplink]
    
  2. Kevin Penrose says:

    The article is about wondershaper, but the install commands say wondersharper. Is that a typo?

  3. Stef Bon says:

    Real traffic shaping is something different than this.

    • Aaron Kili says:

      @Stef

      Yes, this is true. However, the main aim of wondershaper is to simply the whole process. You can use tc, wondershaper’s backend or any other tool, for comprehensive bandwidth shaping.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.