Restricting network bandwidth usage in Linux

Source: Internet
Author: User

One way to limit the network traffic rate is through a command-line tool called Trickle. The trickle command allows you to change the traffic for any particular program by preloading a method that speeds up the socket library at the time the program runs. A good feature of the trickle command is that it runs only in user space, which means that you do not need root privileges to limit the bandwidth usage of a program. To be able to use the bandwidth of the Trickle Program control, this program must use the socket interface of the non-static link library. Trickle can be helpful when you want to rate-limit a program that doesn't have built-in bandwidth control.
Install trickle in Ubuntu,debian and its derived distributions:
$ sudo apt-get install trickle
In Fdora or Centos/rhel (with EPEL repositories):
$ sudo yum install trickle
The basic use of trickle is as follows. Simply place the trickle command (and the rate parameter) before the command you want to run.
$ trickle-d <download-rate>-u <upload-rate>
This allows you to limit the download and upload rate to a specific value (unit kbytes/s).
For example, set the maximum upload bandwidth for your SCP session to KB/S:
$ trickle-u SCP backup.tgz [email protected]_host.com:
If you want, you can use the following command to set the maximum download rate for your Firefox browser by creating a custom launcher (for example, kb/s).
Trickle-d Firefox%u
Finally, trickle can also run in daemon mode, where it will limit the sum of the total bandwidth of all programs that are started by trickle and are running. Start trickle to make it a daemon (for example, trickled):
$ sudo trickled-d 1000
Once the trickled daemon is running in the background, you can start other programs with the Trickle command. If you start a program through trickle, then the maximum download rate for this program will be kb/s, if you start another program through Trickle, then the (download) rate limit for each program will be limited to $ kb/s, and so on.

Limiting the rate of one network interface in Linux
Another way to control your bandwidth resources is to limit the bandwidth on each interface. This is especially useful when you share the upstream bandwidth of your network connection with others. As with others, Linux has a tool to do this for you. That's what Wondershaper did.
Wondershaper is actually a shell script that uses TC to define traffic-tuning commands and uses QoS to handle specific network interfaces. Outbound traffic is designed to limit the rate of outgoing traffic by placing it in a queue of different priorities, and incoming traffic is lost to the rate limit.
In fact, Wondershaper's set goal is not just to increase its bandwidth limit on an interface; when bulk download or upload is in progress, Wondershaper also tries to keep interactive sessions such as SSH low latency. Also, it controls bulk uploads (for example, Dropbox syncing) without "choking" the download and vice versa.
Install Wondershaper in Ubuntu Debian and its derived distributions:
$ sudo apt-get install Wondershaper
Install Wondershaper in Fdora or Centos/rhel (with EPEL repositories):
$ sudo yum install Wondershaper
The basic use of Wondershaper is as follows:
$ sudo wondershaper <download-rate><upload-rate>
For example, the maximum download/upload bandwidth for eth0 is set to 1000kbit/s and 500kbit/s, respectively:
$ sudo wondershaper eth0 1000500
You can also eliminate the rate limit by running the following command:
$ sudo wondershaper clear eth0
If you are interested in the operating principle of wondershaper, you can read its shell script source file (/sbin/wondershaper).

Summarize
In this tutorial, I introduced two different approaches to how to control the bandwidth usage of each application or interface in a Linux desktop environment. These tools are simple to use, providing users with a quick and easy way to adjust or limit traffic. For readers who want to learn more about how to rate control in Linux, refer to the Linux Bible.

Restricting network bandwidth usage in Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.