Last Updated: February 25, 2016
·
4.496K
· ssteynfaardt

Simulate a slow network with high latency on your localhost

Sometimes when a network is slow, it can cause errors that are difficult to debug on your localhost when there is no latency or time outs.

This tip allows you to slow down , or introduce some latency into your network on Linux.

Setup the rate control and delay

sudo tc qdisc add dev lo root handle 1: htb default 12
sudo tc class add dev lo parent 1:1 classid 1:12 htb rate 56kbps ceil 128kbps
sudo tc qdisc add dev lo parent 1:12 netem delay 200ms

Easily update these values according to how big delay you want:

  • sudo tc class add dev lo parent 1:1 classid 1:12 htb rate 56kbps ceil 128kbps
  • sudo tc qdisc add dev lo parent 1:12 netem delay 200ms

Remove the rate control/delay

sudo tc qdisc del dev lo root

See what is configured on an interface

sudo tc -s qdisc ls dev lo

Introduce latency to ethernet or wireless

Replace lo with eth0 / wlan0 to apply a limit to a device

sudo tc qdisc add dev eth0 root handle 1: htb default 12
…

Where eth x or wlan x is the network device you want to apply the latency to.