Most of the time while downloading large files from the internet, you don’t want to disturb the rest of the network from congestion as most of the network bandwidth will be consumed by the one process.
In this article, we will see how to limit network bandwidth in Ubuntu 18.04 LTS using Wondershaper. Wondershaper is a command line utility that helps to limit the bandwidth usage by saving unnecessary bandwidth consumption. Using Wondershaper, you can set the maximum upload and download rate on a specific network interface.
Limit Bandwidth Using Wondershaper
In this section, we will see how to install Wondershaper using Ubuntu Terminal
Step 1: Open the Terminal
In order to install the Wondershaper utility, we will use the Ubuntu Terminal. You can open the Terminal using the search bar in Application Launcher. Alternatively, you can use the shortcut by pressing Ctrl+Alt+T key combinations to launch the Terminal.
Step2: Installing Wondershaper
Wondershaper is available in the official Ubuntu repositories. In the Terminal, run the below command as sudo to install Wondershaper
$ sudo apt-get install wondershaper
There is an alternative method to install Wondershaper in case if you want to have Wondershaper with the latest updates. I am using this method for describing the procedure.
Navigate to the directory using cd command in Terminal.
$ cd /bin
Then add the below command:
$ git clone https://github.com/magnific0/wondershaper.git
Navigate to Wondershaper directory and install it using the below command as sudo:
$ cd wondershaper sudo make install
Step 3: Enable and start the service
Once you have done with the installation, enable the service to allow it to start every time automatically when the system boots. Note that Wondershaper can be run as service similar to other services in Ubuntu.
After enabling the service, also start the service to use it at the current time.
Run the below commands as sudo in the Terminal to enable and start the Wondershaper service:
$ sudo systemctl enable wondershaper.service
$ sudo systemctl start wondershaper.service
Step 4: Verify service
You can verify if the Wondershaper service is active by running the below command as sudo:
$ sudo systemctl status wondershaper.service
In case you want to stop the service, run the below command:
$ sudo systemctl stop wondershaper.service
In case there is a problem with service and you want to restart it, run the below command:
$ sudo systemctl restart wondershaper.service
Step 5: Use Wondershaper
Find the name of the interface on which you want to limit the bandwidth.
You can find the interface name using one of the following commands:
$ ifconfig $ ip link show $ ip addr
To limit the bandwidth for a specific interface, run the command in following syntax:
$ sudo wondershaper -a <interface> -d <rate> -u <rate>
-a: defines interface name
-d: defines download rate in kbps
-u: defines upload rate in kbps
For instance, I want to limit bandwidth for interface eth0 to be 1024kbps for download and 512 kbps for upload, I will run this command:
To clear or remove the bandwidth limits from an interface, run the command s sudo in below syntax:
$ sudo wondershaper -c –a <interface>
If you have installed Wondershaper using GitHub repository, then there is a configuration file wonderhsaper.conf at /etc/conf.d. You can edit using any text editor.
I am using Nano editor to edit that configuration file. Run the below command in the Terminal window:
$ sudo nano /etc/conf.d/wondershaper.conf
Here you can set the interface and define the upload and download bandwidth limit. When done with configurations, save the file and exit.
Make sure to restart the Wondershaper service after making changes in the configuration file.
So that was the simplest way using which you can limit network bandwidth and ensure congestion free network traffic by preventing one single user to consume all the bandwidth.