Resources:
The following commands will add ping/packet loss to all connections to localhost. Very helpful when simulating a bad internet connection or very remote server.
# Add 100ms of latency to localhost (command uses 50ms, resulting in 100ms ping)
> sudo tc qdisc add dev lo root handle 1:0 netem delay 50msec
# Add 3.5% of packet loss
> sudo tc qdisc add dev lo root handle 1:0 netem loss 3.5%
# Add both ping and packetloss
> sudo tc qdisc add dev lo root handle 1:0 netem delay 50msec loss 3.5%
# Reset simulation
> sudo tc qdisc del dev lo root
You can confirm that the configuration is active by e.g. running ping localhost.