MacOS – Forcing macOS Sierra L2TP client to use specific interface

macosNetworkvpn

I've got a WiFi (en0) and Ethernet (en8) connection on my machine. Each interface is on a separate network and en0 has priority over en8.

The gateway for en0 is 192.168.100.1 and for en8 it is 172.20.10.1

There are services I need to access that are only available on the en0 network, and the VPN is only available via en2 network.

I want to be able to force the macOS Sierra L2TP client to use en8. I have successfully added a static route to route the IP address that I want to connect to, to the gateway of en2 and have verified by running trace get <vpn address>

However the connection still fails and when I look at the logs in /var/ppp/ppp.log it looks like the L2TP client is still trying to go through the en0 gateway:

Wed Mar 22 13:53:10 2017 : l2tp_get_router_address 192.168.100.1 from dict 1

Routing Table below:
routing table

Best Answer

Having two default gateways in macOS will result in: the gateway of the interface with the higher priority will be the default one and the other one is disregarded.

To get the order enter in Terminal: networksetup -listnetworkserviceorder.

So remove the default gateway of interface en8 and either add a custom route to the VPN server:

sudo route add -host <VPN-server-ip-address> -interface en8

or

sudo route add -host <VPN-server-ip-address> -link <MAC-of-en8>

or to the network (here the example network: 10.0.0.0/16)

sudo route -n add -net 10.0.0.0/16  172.20.10.1

Depending on the network environment of the VPN-server a second inverted route pointing to your local 172.20.10.0/28 network has to be added there.