tc can be used to simulate network latency on Linux.
$ sudo tc qdisc add dev eth0 root netem delay 100ms
Now every packet that is sent or received via
eth0 is delayed by 100ms. It is possible to add a random offset on top of it, as follows:
$ sudo tc qdisc add dev eth0 root netem delay 100ms 10ms
tc can do a lot more. (StackOverflow was helpful as well.)
If the second
tc qdisc add command does not work, you might want to use
tc qdisc change instead. And when you’re done
tc qdisc del is your friend as well!