Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ardell/957212 to your computer and use it in GitHub Desktop.
Save ardell/957212 to your computer and use it in GitHub Desktop.
ipfw bandwidth throttling
#!/bin/sh
#
# Use ipfw to throttle bandwidth.
# usage:
# ./throttle.sh # Throttle at default (60KB/s)
# ./throttle.sh 5 # Throttle at custom speed (5KB/s)
# ./throttle.sh off # Turn throttling off
# flush rules
ipfw del pipe 1
ipfw del pipe 2
ipfw -q -f flush
ipfw -q -f pipe flush
speed=60
[ ! -z $1 ] && speed=$1
if [ "$1" == "off" ]; then
echo "disabling BW limit."
exit
else
# simulate slow connection <to specific hosts>
echo "enabling bw limit at ${speed}KByte/s"
ipfw add pipe 1 ip from any to any
ipfw add pipe 2 ip from any to any
ipfw pipe 1 config bw ${speed}KByte/s
ipfw pipe 2 config bw ${speed}KByte/s
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment