Using networksetup to add static route(s) to a Mac OS VPN
- February
- 4
10:32 am Cycling
These commands were executed in a user context, no sudo needed. The routes added to your VPN connection should survive a reboot.
First I list out my network connections to make sure I have the name correct:
$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Ethernet
Wi-Fi
home.mydomain.net
*INT
Bluetooth PAN
Thunderbolt Bridge
COGENT-HSLC
GUEST
COGENT-ACCESSPA
Verizon-DSL
DMZ
MGMT
STORAGE
55 with Default
55
52
52 with Default
HSLC
I want to add a route to home.mydomain.net so I do:
$ networksetup -setadditionalroutes home.mydomain.net 192.168.2.0 255.255.255.0 192.168.1.71
I happen to know that the IP address on the other side of the gateway is 192.168.1.71. If you don't know, connect to your vpn and look in the routing table with:
$ netstat -nr -f inet
If you want more than one route you have to combine them all into one command. You can't add them one at a time as the current route will override the previous. So to add two routes I would do:
$ networksetup -setadditionalroutes home.mydomain.net 192.168.2.0 255.255.255.0 192.168.1.71 192.168.3.0 255.255.255.0 192.168.1.71
If your VPN name has a space in it, put quotes around the name like:
$ networksetup -setadditionalroutes "home vpn" 192.168.2.0 255.255.255.0 192.168.1.71
Finally, to delete all the additional routes just leave the route blank.
$ networksetup -setadditionalroutes "home vpn"
To check your work:
$ networksetup -getadditionalroutes "home vpn"
« Systemd Mount Point Management | Moving a CentOS 7 VM from VMWare to Xenserver » |