Search This Blog

Wednesday, 5 August 2015

Simulate Network Latency, Packet Loss, and Low Bandwidth on Mac OSX

OSX used to contain the binaries to configure ‘dummynet’ from FreeBSD which has the capability to do WAN simulation.

Mavericks no longer has support for dummynet but still has the code in the backend.  Find and copy the IPFW binary from an older machine into /sbin and you're good to go.


Inject 250ms latency and 10% packet loss on connections between workstation and web server ( and restrict bandwidth to 1 Mbit/s.

# Create 2 pipes and assigned traffic to/from:
$ sudo  ipfw add pipe 1 ip from any to
$ sudo  ipfw add pipe 2 ip from to any
# Configure the pipes we just created with latency & packet loss:
$ sudo  ipfw pipe 1 config delay 250ms bw 1Mbit/s plr 0.1
$ sudo  ipfw pipe 2 config delay 250ms bw 1Mbit/s plr 0.1

$ ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=63 time=515.939 ms
64 bytes from icmp_seq=1 ttl=63 time=519.864 ms
64 bytes from icmp_seq=2 ttl=63 time=521.785 ms
Request timeout for icmp_seq 3
64 bytes from icmp_seq=4 ttl=63 time=524.461 ms

$sudo  ipfw list |grep pipe
  01900 pipe 1 ip from any to out
  02000 pipe 2 ip from to any in
$ sudo  ipfw delete 01900
$ sudo  ipfw delete 02000
# or, flush all ipfw rules, not just our pipes
$ sudo ipfw -q flush

Round-trip is ~500ms because it applied a 250ms latency to both pipes, incoming and outgoing traffic.

Packet loss is configured with the “plr” command.  Valid values are 0 – 1.  In our example above we used 0.1 which equals 10% packetloss.