How I can limit Download/Upload bandwidth?

89,643

Solution 1

Limiting single interface is easy, but global rate limits need more complex rules as do application based rules. I'm not saying that it can't be done, but it requires quite a bit digging in to the internals of the networking.

Here is a quick How to on setting up a per interface limit

If you really want to set up application based rules, you should look in to some firewall framework, like shorewall, which have helper features to configure shaping. Even with these tools, it requires quite bit of forethought and testing to get it in to place. Doing something like this ad-hoc is not yet quite that easy.

Solution 2

Although this is an old question, I came across this when looking for an answer to the same question. The OS and interface limits are already addressed in an earlier answer, so here is a way to set up application specific limits. Use an application called trickle. So do sudo apt-get install trickle. You can limit upload/download for a specific app by running

trickle -u (upload limit in KB/s) -d (download limit in KB/s) application

This will launch the application with the specified limits. You can also specify "smoothing" time, so that trickle samples over the desired time period in case your application has bursts of bandwidth consumption and you'd like the bursts to be allowed so long as the average is within your specifications.

Solution 3

If you want to limit bandwidth for a specific IP address, you can use this:

tc qdisc add dev eth1 root handle 1: htb default 12
tc class add dev eth1 parent 1: classid 1:10 htb rate 2500kbps
tc class add dev eth1 parent 1: classid 1:11 htb rate 2500kbps
tc class add dev eth1 parent 1: classid 1:12 htb rate 5000kbps

tc filter add dev eth1 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.2.105 flowid 1:10
tc filter add dev eth1 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.2.106 flowid 1:11
Share:
89,643

Related videos on Youtube

yevhene
Author by

yevhene

Updated on September 17, 2022

Comments

  • yevhene
    yevhene over 1 year

    How I can limit Download/Upload bandwidth for:

    • Entire OS.
    • One network interface.
    • Single application.
  • Glutanimate
    Glutanimate about 11 years
    Thank you very much! This solution is perfect for controlling bandwidth on a per-application basis. Please don't ever hesitate to post an answer, even if the question is years old. For future reference: You might be presented with an error message like trickle: Could not reach trickled, working independently: No such file or directory. You can remove this warning by executing trickle in standalone mode with trickle -s.
  • Anonymous Mouse
    Anonymous Mouse about 11 years
    How do I remove the limit limited by trickle?
  • Gabe Troyan
    Gabe Troyan about 11 years
    Trickle will run the application for you with the limits being enforced. So all you have to do is restart the application without using the trickle command.
  • Ali
    Ali about 11 years
    thanks a lot for this answer it was the exact thing i was searching for
  • oligofren
    oligofren almost 9 years
    that was pretty convoluted. A few #comments would go a long way. You could for instance add links or explanations for qdiscs, classids, htb, etc.
  • Ken Sharp
    Ken Sharp almost 9 years
    So, by default, the above limits everything to 5000 kbps unless filtered into some other queue? What about if we don't want to limit everything?
  • Hochopepa
    Hochopepa over 7 years
    This answer still rocks!
  • Soron
    Soron about 7 years
    Exactly what I needed, when trying to simulate a slow network connection.
  • Arash
    Arash almost 7 years
    wondershaper isn't working I don't know why (even wondershaper eth0 1000 1000 has no internet bandwidth. I need to limit One network interface. bandwidth not only specific applications. how can in do that?
  • Arash
    Arash almost 7 years
    wondershaper isn't working I don't know why (even wondershaper eth0 1000 1000 has no internet bandwidth. I need to limit all of the eth0 bandwidth not only specific applications. how can in do that?
  • isaaclw
    isaaclw almost 7 years
    Does this affect children application of the program I'm launching?
  • occulus
    occulus almost 4 years
    Btw, when I use trickle to limit bandwidth for aria2c, it works, but the CPU use for the core running that process is close to 100% pretty much the entire time (on Raspbian Buster). Something to bear in mind.
  • Seperman
    Seperman over 2 years
    Note that this only works when your app is using gLIBC syscalls for networking. If you app is written in Go for example, it is not using gLIBC syscalls and trickle won't work on it.