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 && 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.

1 Answer

  1. George- Reply


    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:

    1. Bring your network interfaces down:

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

    3. 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/://');
            sudo ifconfig "$i" down;
        sudo route -n flush;
        for i in $(ifconfig | egrep -o "^[a-z].+\d{1}:" | sed 's/://');
            sudo ifconfig "$i" up;

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>