73

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.

67

You can throttle the network bandwidth on the interface using the command called tc Man page available at http://linux.die.net/man/8/tc

For a simple script, try wondershaper.

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

62

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 
  • 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 '15 at 16:22
  • 2
    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 '16 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 '17 at 14:19
  • 5
    Wondershaper is very outdated: Wondershaper Must Die (Bufferbloat.net) – Niklas Holm Oct 4 '17 at 5:53
10

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.

  • 1
    Were you referring to a particular section in it? – rogerdpack Apr 23 '15 at 16:21
  • 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 :) – erm3nda Dec 22 '15 at 16:27
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.

5

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

protected by Community Sep 4 '16 at 1:33

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.