Restart network config from terminal I've been having a problem where my macbook won't reconnect to the internet after I turn off my work VPN. A simple reboot fixes this, but I was wondering if there was a way I could restart the network configs, or clear cache (not sure exactly what the problem is) from the command line - without having to do a reboot?

I've tried the following, without success

$ ifconfig en0 down &amp;&amp; ifconfig en0 up


Is there a way to reset the network config to whatever the default values are after a reboot?

Edit: This doesn't happen every time, I'm not exactly sure what chain of events triggers it.
Lack of network access after disconnecting from a VPN can be a symptom of a routing issue. If your VPN client doesn't disconnect cleanly, the gateway that directs your traffic to the virtual network can sometimes be left in place, effectively routing your traffic to a dead end.

I'd suggest bringing your interfaces down, flushing the routing table of gateway entries, and bringing them up again:


Bring your network interfaces down:

for i in $(ifconfig | egrep -o "^[a-z].+\d{1}:" | sed 's/://'); do sudo ifconfig "$i" down; done

Flush the routing table: sudo route -n flush.
Bring your interfaces back up again: (repeat step 1 with up instead of down).


If you want a reusable Bash function for this that you can drop into your .bashrc (or wherever), you could save the following:

resetroute () {
    echo "Flushing routes...";
    for i in $(ifconfig | egrep -o "^[a-z].+\d{1}:" | sed 's/://');
    do
        sudo ifconfig "$i" down;
    done;
    sudo route -n flush;
    for i in $(ifconfig | egrep -o "^[a-z].+\d{1}:" | sed 's/://');
    do
        sudo ifconfig "$i" up;
    done
}