Skip to content

Instantly share code, notes, and snippets.

@reebalazs
Last active December 18, 2015 08:38
Show Gist options
  • Save reebalazs/5755018 to your computer and use it in GitHub Desktop.
Save reebalazs/5755018 to your computer and use it in GitHub Desktop.
How to simulate network latency and errors on macosx
#! /bin/sh
# --
# How to simulate network latency and errors on macosx.
#
# After this you can access the 127.0.0.10 as an alias
# to your localhost, but with a roundtrip delay.
#
# delay 150ms adds the delay to the given pipe (*)
# plr 0.05 simulates packet loss.
# bw 1Mbit/s limits the bandwidth.
#
# Use "ipfw list" and "ipfw delete" to remove this setup.
#
#
# (*) According to my tests the delay will be more then 2x
# the value you entered, so best to check the result with ping.
#
# --
sudo ifconfig lo0 inet 127.0.0.10 netmask 255.255.255.255 alias
sudo ipfw add pipe 1 ip from any to 127.0.0.10
sudo ipfw add pipe 2 ip from 127.0.0.10 to any
sudo ipfw pipe 1 config delay 150ms bw 1Mbit/s plr 0.05
sudo ipfw pipe 2 config delay 150ms bw 1Mbit/s plr 0.05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment