Skip to content

Instantly share code, notes, and snippets.

@hydra35
Created August 24, 2012 03:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hydra35/3445140 to your computer and use it in GitHub Desktop.
Save hydra35/3445140 to your computer and use it in GitHub Desktop.
destroy NAT gateway on OSX
#!/bin/bash
# All these steps look excessive but address
# network instability issues created by not doing them
gwdev=`netstat -nr | grep default | awk '{ print $6 }' | head -1`
if [ -z "$gwdev" ]; then
gwdev=en1
fi
killall natd
/sbin/ipfw delete 100 divert natd ip from any to any via $gwdev
sysctl -w net.inet.ip.forwarding=0
ifconfig $gwdev down
ifconfig en0 down
route delete default -interface bridge0 -ifscope bridge0
ifconfig bridge0 172.20.0.1 delete
ifconfig bridge0 deletem en0
ifconfig bridge0 destroy
ifconfig en0 up
ifconfig $gwdev up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment