Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@blister
Created December 14, 2010 18:19
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save blister/740829 to your computer and use it in GitHub Desktop.
Save blister/740829 to your computer and use it in GitHub Desktop.
Bash script to add a delay to the localhost interface on Linux machines
#!/bin/bash
# Copyright 2010 Eric Ryan Harrison <me@ericharrison.info>
# Inspired by:
# http://daniel.haxx.se/blog/2010/12/14/add-latency-to-localhost/
if [ -n "$1" ]
then
if [ "$1" = "off" ]
then
tc qdisc del dev lo root
else
tc qdisc add dev lo root handle 1:0 netem delay $1msec
fi
else
echo 'Usage: localdelay [TIME_IN_MILLISECONDS|off]'
echo 'Example:'
echo ' localdelay 20'
echo ' This will add a 20 millisecond delay to localhost'
echo ' and pings will take 40+ms to respond.'
echo ' localdelay off'
echo ' Turns off delay.'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment