HomeOS X HelpNetworkingAdd a permanent static route in high sierra

4.1. Add a permanent static route in high sierra

Adding a static route using the route add command does not add a route persistently. After you reboot the system, the static route is lost and you have to reapply the command.

I suggest to use networksetup which works persistent and also in separate network locations.

First, open your terminal of choice i.e. iTerm2.app or Terminal.app

  • list your network locations:

networksetup -listlocations

  • choose your desired network location:

sudo networksetup -switchtolocation <locationofchoice>

  • list "devices" called networkservices

networksetup -listallnetworkservices

  • list persistent routes on "device" of choice i.e. "Ethernet"

networksetup -getadditionalroutes Ethernet

  • add your route to "Ethernet"

sudo networksetup -setadditionalroutes Ethernet

  • list persistent routes on "Ethernet" again to check

networksetup -getadditionalroutes Ethernet

To see all commands:

networksetup -help or
networksetup -printcommands

To reset all routes, simply use sudo networksetup -setadditionalroutes <INTERFACE> with no addresses.


sudo networksetup -setadditionalroutes VPN

If you have a VPN which needs a static route, for example your home network is on, which incidentally is the same as the remote network your connected to using VPN and you need to reach a server on which is on the remote network, you would use the above command.

The above command will create a route for the interface called VPN to point traffic for the 198 address across the gateway 254. Don't forget to switchtolocation first!

This page was: Helpful | Not Helpful