109

We are hosting an application on remote server. We need to test it with a limited network bandwidth (for users with bad Internet access).

Can I limit my internet bandwidth? For instance: 128 KB per second.

This question focuses on system-wide or container-wide solutions on Linux. See Limiting a specific shell's internet bandwidth usage for process- or session-specific solutions.

6 Answers 6

97

You can throttle the network bandwidth on the interface using the command called tc Man page available at http://man7.org/linux/man-pages/man8/tc.8.html

For a simple script, try wondershaper.

An example from using tc: tc qdisc add dev eth0 root tbf rate 1024kbit latency 50ms burst 1540

4
93

As noted in previous answer, wondershaper does the job easily. I include the information from above link by Jwalanta Shrestha

apt-get install wondershaper

wondershaper - An easy tool to limit bandwidth of a particular interface.

$ sudo wondershaper {interface} {down} {up}

the {down} and {up} are bandwidth in kpbs

So for example if you want to limit the bandwidth of interface eth1 to 256kbps downlink and 128kbps uplink,

$ sudo wondershaper eth1 256 128

To clear the limit,

$ sudo wondershaper clear eth1 
7
  • 2
    Ideally, you should have just edited the original answer instead of adding a new one. This is the standard policy. Anyways, +1 for your answer, for it does add information to the answers.
    – shivams
    Jun 11, 2015 at 16:22
  • 3
    This is very useful if you are tethering mobile data and have a fair-use limit (and you have to buy new bundles after, the case for Lycamobile). On video streaming websites like YouTube, the whole video is directly loaded if you have enough bandwidth. If you limit the bandwidth, the video will automatically switch to a low resolution and download what you are watching only, which saves data if you don't want to watch everything.
    – baptx
    Apr 27, 2016 at 21:10
  • 2
    Usefull also for uploading big files, as it not only limit bandwidth, but also prioritize traffic. So that when uploading 10gb file you still can use SSH.
    – PeterM
    Mar 9, 2017 at 14:19
  • 8
    Wondershaper is very outdated: Wondershaper Must Die (Bufferbloat.net) Oct 4, 2017 at 5:53
  • 3
    If someone thinks Wondershaper must die, can they post an answer using OpenWrt and then link to it in the comments here? This answer was the easiest to understand implement, it doesn't matter much to me that it's an old tool. I took a quick look at OpenWrt (suggested by the article, "Wondershaper Must Die," and I figured it'd be at least a half hour of reading documentation and mucking around to figure out how to replicate this simple answer. May 7, 2021 at 19:49
11

Limiting network resources based on some criterias is the subject of QoS. There are several different ways to control user traffic on Linux systems.

There is a good How-to about advanced routing techniques and traffic control on Linux by Bert Hubert.

3
  • 2
    Were you referring to a particular section in it?
    – rogerdpack
    Apr 23, 2015 at 16:21
  • 1
    If you don't wanna change system settings, just install squid3 proxy then set your "limited" aplication through proxy. For cli app's you can set torsocks or proxychains, and for heavy GUI app's you can also install Fiddler mono, so yes... there a are some ways to control everything :)
    – m3nda
    Dec 22, 2015 at 16:27
  • 1
    (this is a link only answer) Oct 1, 2019 at 19:08
8

You can also use iptables hashlimit module. Here is a simple example:

iptables -A FORWARD -m hashlimit --hashlimit-above 512kb/sec --hashlimit-burst 1mb --hashlimit-mode srcip,dstip --hashlimit-name bwlimit -j DROP

That rule limits traffic that pass through FORWARD chain as 512kb/sec with 1mb burst for each source and destination pair.

Check hashlimit section of iptables manual for more information.

http://ipset.netfilter.org/iptables-extensions.man.html

7

If you already have an Apache setup somewhere, you can use mod_bw, which also works on proxied connections (i.e. Apache just forwards everything to the proper server, but slows the responses down.)

6

Dummynet does what you want and more, you can even control the latency, random packet loss and lots more.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .