Throttling Bandwidth in Mac OS X

I recently had the need to simulate the speed of a home broadband connection (10Mb/s down, 64Kb/s up) in an environment with 100Mb/s down and 60Mb/s up. With Mac OS X this is quite easy to do.

First of all, if you’re throttling HTTP traffic only, it’s probably easier to use a debugging proxy like Charles to do so. Otherwise, Mac OS X includes a tool called ipfw (ipfirewall) built in which is able to throttle traffic system-wide.

throttle.sh

#!/bin/sh
 
LIMIT_DOWN="10Mbits/s"
LIMIT_UP="64Kbytes/s"
 
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root." 1>&2
   exit 1
fi
 
ipfw pipe 1 config bw $LIMIT_DOWN
ipfw pipe 2 config bw $LIMIT_UP
ipfw add 1 pipe 1 tcp from any to me
ipfw add 2 pipe 2 tcp from me to any

The script above will throttle the connection to 10Mb/s down and 64Kb/s up. This script must be run as root via the sudo command:

chris@macbookpro:~/bin$ sudo ./throttle.sh

To undo the throttling, use the following script.

unthrottle.sh

#!/bin/sh
 
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root." 1>&2
   exit 1
fi
 
ipfw delete 1
ipfw delete 2

Again, run the script as root.

chris@macbookpro:~/bin$ sudo ./unthrottle.sh

Related Posts:

Comments are closed.