How to control bandwidth in Linux?

easy-guide-to-bandwidth

Trickle and WonderShaper:

When we start working on a lot machines specifically Linux servers, it is interesting to know how we can control or limit the bandwidth. This can be useful in different contexts, for an instance, as part of a dedicated server or shared server infrastructure where we can control a download or app taking all traffic over other network users. It could very well put QoS or other technologies, but the tools that we are going to see in this post allow putting a limitation on the bandwidth which normally used pretty quickly and easily in Linux.

Limiting the bandwidth per interface via WonderShaper:

WonderShaper is a small, lightweight and very simple tool with only one function to limit the bandwidth that can be used by a given network interface of Linux machine. For example, Incoming bandwidth – we can indeed limits “download” and outgoing bandwidth “upload” with different values and have the different settings per interface. The installation part is also easy:

For Debian and Ubuntu machine run the following command:

For CentOS / RHEL machine:

The use of this command is the most basic, following is the general syntax:

Note: here the limits are included in kilobits per second and not in kilobytes as it is more common to do so.

For example, to limit the bandwidth to 1 MB/s in download and 200 KB/s upload on “eth0”

Note: 1 megabyte equals to 8192 kilobits and 200 KB/s to 1600 kilobits. There are very efficient converters available on the Internet; here we used “Bit Calculator” for our conversion.

For an instance, a test may then be run by downloading an archive form the Internet to see that the bandwidth is limited. Also note that if you have multiple interfaces then let other interfaces work without limitation or on the contrary, more or less restrictively by using the same syntax. It just suffices for that to change the interface of the name in the command used.

To blow any restriction on a given interface, you can simply use the following command line. For example, the “eth0” interface:

The designated interface will no longer have any restrictions.

Limiting the bandwidth by using Trickle:

Although it also acts on the limitation of bandwidth for upload and download, Trickle corresponds to other contexts since applies using only when using command line i.e. ad hoc basis. If you want to download an archive on the Internet and also want to limit the bandwidth used by the download, you can use this tool to limit the bandwidth.

Here we start by installing it with the following command lines for Debian and Ubuntu:

For CentOS / RHEL machine:

Once install you can use it; you just have to precede your limitation order that is desired. For example, if you want to download the archive of the latest WordPress by limiting bandwidth used in download to 10 kilobytes per second:

You will then see the download proceed normally, but the bandwidth will be limited to 10 KB/s. You can also perform a limit on the upload independently with the “-u” instead of “d” or the two at the same time such as the following:

Here we are sending an archive via scp to a remote server and upload bandwidth may not exceed beyond 20 MB/s and download bandwidth cannot exceed than 10 MB/s.

This is a limitation that will end once the limitation order is completed.

If you do not wish to enter our limitation whenever we entered a command, you can use trickle in daemon mode. We will start with beginning of the daemon indicating our bandwidth limit, for example, 50 MB/s in download and no limit upload:

Then we’ll just grab “trickle” before each command on which we want to apply this restriction:

If the same command is issued without the “trickle” in front, no restrictions will be applied.

These two commands are very easy to use and can be quite useful when bandwidth is low and the multiple users share!

About Paul Lopez

Paul Lopez, a technology writer and sales & marketing executive at bodHOST.com, a cloud & dedicated server hosting company based in New Jersey.
This entry was posted in Dedicated Server Hosting, FAQs and tagged , , , , , . Bookmark the permalink.