Traffic management with WonderShaper

Requirements:

Introduction

WonderShaper is a software available for Linux based computers. It allows easily to shape the bandwidth available on an interface to a defined value.
This can be useful to avoid congestion in your network and to allow a server to use a certain amount of bandwidth.
You can configure the upload and download bandwidth available on your Ethernet card individually.

Installation

On Ubuntu/Debian

Install WonderShaper by typing the following command:

sudo apt-get install wondershaper

On CentOS/Fedora

Install WonderShaper on CentOS/Fedora (on a system with the EPEL-Repository) with the following command:

sudo yum install wondershaper

Usage

Once you have installed WonderShaper it is ready to run. You just need to start it with the following command and options:

sudo wondershaper -a <network interface> -d <downspeed> -u <upspeed>

The values downspeed and upspeed represent the available bandwidth for Download and Upload in kbits.

This means, if we want to shape the available bandwidth on our servers network card eth0 to 300 Mbit/s both in upload and download, we launch the application with the following command: wondershaper -a eth0 -d 300000 -u 300000.
The available bandwidth of your server will now be shaped automatically.

To stop WonderShaper, type the following command:

sudo wondershaper clear <network interface>

So when we want to stop the shaping on eth0, we type sudo wondershaper clear eth0.
The traffic shaping will stop and you can use again available bandwidth on the interface.
Be careful about the name of your interface, as it may be different depending of your distribution. You can check the list of interfaces with the command: ifconfig.

Launch WonderShaper automatically on boot with SystemD

To launch WonderShaper automatically during the boot of your server, you can configure SystemD to start it automatically.

SystemD configuration files are located in the folder /etc/systemd/.
We need to create a new wondershaper.conf and put the following content in it:

[wondershaper]
# Adapter
#
IFACE="eth0"

# Download rate in Kbps
#
DSPEED="2048"

# Upload rate in Kbps
#
USPEED="512"

To start WonderShaper automatically during boot, we need a SystemD script, which has to be located in the directory /usr/lib/systemd/system/.
We create the file wondershaper.service in the directory and put the following content into it:

[Unit]
Description=Bandwidth shaper/Network rate limiter
After=network.target
Wants=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/systemd/wondershaper.conf
ExecStart=/usr/bin/wondershaper -a $IFACE -d $DSPEED -u $USPEED
ExecStop=/usr/bin/wondershaper -c -a $IFACE

[Install]
WantedBy=multi-user.target

Now we have to start the service with the following command sudo systemctl start wondershaper.service.

To make sure systemD starts WonderShaperr automatically during boot, we have to enable the service: sudo systemctl enable startup.service Now our bandwidth shaper will start automatically on each boot and shapes the bandwidth of your server to its allowance.