Skip to content

Instantly share code, notes, and snippets.

@SupaFuzz
Last active July 4, 2022 19:00
Show Gist options
  • Save SupaFuzz/a26d19d25ed2f57feaf282a127135d7c to your computer and use it in GitHub Desktop.
Save SupaFuzz/a26d19d25ed2f57feaf282a127135d7c to your computer and use it in GitHub Desktop.
simulate bad network on linux

how to simulate slow / messed up network

You might need to simulate crappy wifi, or spotty cell or otherwise "there but just barely or not really" network connectivity, so as to make sure your app or whatevz handles that gracefully.

Presuming your server is on linux, this is the long and short of it:

# add a rule limiting bandwidth and adding latency
# to the network interface serving your thing
# mine is 'enp2s0', but maybe yours is 'eth0'
# or what have you
root@server> tc qdisc add dev enp2s0 root tbf rate .5mbit burst .5mbit latency 100ms

# turn the rule back off and return to normal
root@server> tc qdisc del dev enp2s0 root tbf rate .5mbit burst .5mbit latency 100ms

background

you're using the tc (traffic control) shell command which you probably already have as part of your distro install, but you might have to go looking. If you don't have it, the iproute package is a good place to start.

helpful links

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