Skip to content

Instantly share code, notes, and snippets.

@anders94
Last active February 27, 2018 18:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anders94/5715a78bcbc754f498fa to your computer and use it in GitHub Desktop.
Save anders94/5715a78bcbc754f498fa to your computer and use it in GitHub Desktop.
Simulate a Terrible Internet Connection

Simulate a Terrible Internet Connection

The Linux networking stack is the Swiss Army Knife of the tech world.

Using iptables, drop a random 10% of incoming and outgoing packets:

iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP
iptables -A OUTPUT -m statistic --mode random --probability 0.1 -j DROP

To reset:

iptables -D INPUT -m statistic --mode random --probability 0.1 -j DROP
iptables -D OUTPUT -m statistic --mode random --probability 0.1 -j DROP

Same thing using tc but adding some delay, reorders and dups:

tc qdisc add dev eth0 root netem delay 50ms 20ms distribution normal
tc qdisc change dev eth0 root netem reorder 0.02 duplicate 0.05 corrupt 0.01

To reset:

tc qdisc del dev eth0 root netem

That's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment