Traffic shaping or limiting the download & upload speeds of a network is usually performed by the ISPs for maintaining a QoS (“Quality of service”). For instance, I have an ADSL connection setup with a wireless router and it has a monthly bandwidth limit of 20GB. If my monthly network usage exceeds this limit, then the ISP slows it down (pretty hard).
So to save unnecessary bandwidth consumptions by applications (Web Browser or VOIP tools such as Skype etc), there can be situations where limiting the network speed by yourself is a necessity.
If you use Ubuntu Linux, though there aren’t that many we can use (or at least that I’m aware of) but for its simplicity and ease of use, “Wondershaper” is a very handy utility. It’s a command-line one and lets you apply network traffic throttling temporarily or permanently.
Main features …
*. Change upload and download speeds.
*. Can be applied to each network interface manually (if you have more than one network connection).
*. As said, you can add bandwidth throttling temporarily or can let it run when the system boots up so the network speed will be throttled every time automatically.
*. Easily remove the traffic shaping anytime you want.
Yup, that’s pretty much it!.
You can install “Wondershaper” in Ubuntu 12.10, 12.04 Precise Pangolin, 11.10 Oneiric Ocelot, 11.04 Natty Narwhal, 10.10 and 10.04 by first using the below command in your Terminal window.
sudo apt-get install wondershaper
How to use it?
To limit a network traffic with Wondershaper, you can use something like the below command in your Terminal window.
sudo wondershaper your-network-interface-id download-speed upload-speed
Please replace ‘download-speed’ and ‘upload-speed’ with your preferred values (has to be in “Kilobits per second”, kbps).
For my needs, I’ll use something like the below command.
sudo wondershaper wlan0 512 128
Setting up …
As said earlier, we can setup Wondershaper in two ways. Either temporarily or permanently.
Before doing anything there are few things that you have to know such as:
A. It’s real speed (as claimed by the ISP).
B. The network interface or the hardware “id”.
C. The required (throttled) download/upload speeds.
Getting the “real” network speed …
*. Now I assume that you already know the speed of your Network connection. But if you don’t know it, then you can use some sort of an online test or you can use QSpeed test (desktop based app that supports both GNU/Linux and Windows) or any other tool that you’re aware of.
Figuring out the network interface name …
*. So after figuring that out, now we need to know the network interface used by GNU/Linux OS.
In simple terms, a network interface in GNU/Linux is an Alias assigned by the OS to easily identify the network hardware. And depending on your hardware the network interface name changes.
For instance, if you use an Ethernet adapter/card then usually it’s called “eth0”. If you have more than one, then they’re named “eth0, eth1, eth2” etc. If you have a Wi-Fi router based network setup (such as mine) then the Wi-Fi adapter is called “wlan0” (“wlan0, wlan1, wlan2” etc if you have more than one).
But luckily, in GNU/Linux you can easily identify the currently used network interface name using a command-line tool called “route”. Now to keep the article as simple as possible, I’ll try not to explain everything. So to get the active network interface’s name (with Internet access), open your Terminal and enter the below command.
This should give you an output similar to the below one, but again, depending on your hardware and configuration, the output will change.
This should give you some information about network setup in your GNU/Linux installation. It has divided the screen into few portions such as: Destination, Gateway (with the IP addresses), Genmask, Flags …. “Iface”.
Now in this output under “Destination” heading locate the text “default” and whatever the name displayed under “Iface” for that line is your currently used network name (as shown below).
As for this example, my network interface name is “wlan0” (as I’m using a Wi-Fi adapter).
Preferred network speeds for throttling …
3. Now since I know my Internet connection’s speed (2Mbps for download and 512Mbps for upload), its name (“wlan0” as for this example), the only thing that’s missing is the speeds that I want it to be slowed down to.
So let’s say that I wanted to slow it down to 512 Kbps for downloads and 128 Mbps for uploads (slowed down 400%). To apply these settings temporarily, I’ll open my Terminal and enter the below command.
sudo wondershaper wlan0 512 128
If you want to remove the speed limits applied, then use the below command (changes should be applied almost immediately).
sudo wondershaper remove wlan0
Again, replace your own network interface with “wlan0”.
Applying changes permanently …
To make the changes permanent (can be removed), all we gotta do is just use the command that we used to apply changes temporarily and paste it in a configuration file called “interfaces“. But as a safety precaution, let’s backup it first.
For that, open your Terminal window and enter the below command.
sudo cp /etc/network/interfaces /root/interfaces-backup-file
This will backup the file called “interfaces” in your Root’s (administrator account) Home folder and re-name it to “interfaces-backup-file”.
If you wanted to replace it later (say that after editing the original file you ran into some troubles, yikes!), then you can use the below command.
sudo cp /root/interfaces-backup-file /etc/network/interfaces
Anyhow, open your Terminal and enter the below command to edit the original “interfaces” configuration to make the changes permanent.
sudo gedit /etc/network/interfaces
This should open a configuration file with 2 lines (might change depending on your configuration) as shown below.
Now copy & paste the below two lines of commands into the file.
up /sbin/wondershaper wlan0 512 128
down /sbin/wondershaper remove wlan0
Again, replace the network interface name (marked in Blue), download speed (marked in Green), upload speeds (marked in Orange) according to your configuration. But don’t change anything else. After that, hit the “save” button and close it.
To check if it’s working, reboot your PC and then try downloading/uploading something and observe the speeds. That’s it!.
If you want to temporarily disable the speed throttles, then use the below command.
wondershaper remove wlan0
Again, change replace your network interface name accordingly.
If you want additional information, then after installing it, please go to the below location first.
Once inside that folder, double click on the file called “Readme.Debian.gz”, extract its content and double click on the file called “README.debian” and read it. It includes the above steps that I wrote above. You can also visit this WonderShaper home page for updates and news as well.
Although my rambling might makes it look a bit complicated, yet in truth, if you’re looking for an easy to use, command-line based network traffic shaping tool that can be used in Ubuntu (including GNU/Linux in general), then “Wondershaper” is truly a life saver!. Enjoy.