How to throttle bandwidth on a Linux network interface?

Is there a way to constrain the bandwidth on a NIC in linux? I'd like to be able to simulate an arbitrarily slow connection.


Solution 1:

The netem kernel module, controlled by iproute.

You need to compile Netem with the kernel:

Networking -->
   Networking Options -->
     QoS and/or fair queuing -->
        Network emulator

Once the netem module loaded, iproute's tc allows you things like:

tc qdisc add dev  tap0 root netem delay 50ms loss 50% 

(50 % packet loss, extra delay of 50 ms)

Solution 2:

Client side, right?

trickle should do what you want. If you're running Ubuntu (or Debian, I think), you can install it with sudo apt-get install trickle, and then run it. trickle -s -d 10 -u 10 firefox (or so, I haven't used it in a while) would run firefox, limiting its download and upload speed to 10 kilobytes a second.

Solution 3:

I found a way to avoid my box from eating all the bandwidth available on network using a tool called 'wondershaper' in ubuntu. I hope it exist in other linux destros too. I can limit the bandwidth what my linux home pc can consume using following command.

sudo wondershaper eth0 1000 200

This limits the download limit to 1000 kilobits and uplaod to 200 kilobits. Refer to the man pages of wondershaper for more information/options.

Solution 4:

NIST make a network simulator called NistNet.

http://snad.ncsl.nist.gov/nistnet/ (link seems dead)

http://cs.ecs.baylor.edu/~donahoo/tools/nistnet/

NistNet lets you make a router that emulates a comms link of your choosing.

For simplest operation you have it on a box with two NIC's between two networks.

For example, I had an application that had to work over a satellite link.

Data could go over the a 2Mbps link with BIG latency. Control had to go over a 128kbps link, with the same latency.

NistNet helped to get it all working on 128kbps.

Using NistNet I could simulate not only the bandwidth, but also the latency, and it will also drop packets for you, simulating a busy or unreliable link.

If you want to simulate an abitrary connection, don't just constrain the bandwidth, wind the latency up too.

Don't forget to fragment packets either. You can set nice small MTU's on the phony link.

IIRC adding packet jitter will let you find out if you can cope with out-of order packets.

Solution 5:

I've personally used wondershaper in the past for this, though it was written for an opposite use case - making the most of your ADSL connection.

I'll have to try the others mentioned here though.