I use my Ubiquiti USG for Remote User VPN Using L2TP, but L2TP does not provide routing information to the client, so I needed a way to automatically create routes when the VPN connection fires. Thankfully, this is pretty easy in macOS (and Linux).
The /etc/ppp/ip-up
file, if present, triggers every time a PPP (L2TP is based on PPP) connection is made, thus making it easy to trigger a route command when a connection is established.
My /etc/ppp/ip-up
looks like this:
#!/bin/sh
/sbin/route add -net <my home network subnet>/24 -interface $1
Replace <my home network subnet>/24
with your network information, and you should be ready to go.
Note: This doesn’t diffenciate if you have several L2TP VPN connections, and the script runs regardless of which connection you use. I am sure there are ways of doing different routes based on which connection is triggered, but I haven’t had a need to do that so far"
Running netstat -rn
after making a connection, should now show a line similar to the one below, where xxx.xxx.xxx is your remote subnet, routed over a ppp interface
~ netstat -rn
Routing tables
Internet:
Destination Gateway Flags Netif Expire
...
xxx.xxx.xxx ppp0 USc ppp0
...