Home → OS X Help → Networking → Add 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 192.168.1.0 255.255.255.0 10.0.0.2
- 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.
Example:
sudo networksetup -setadditionalroutes VPN 192.168.1.198 255.255.255.255 192.168.1.254
If you have a VPN which needs a static route, for example your home network is on 192.168.1.0, which incidentally is the same as the remote network your connected to using VPN and you need to reach a server on 192.168.1.198 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!