[Mac] OpenVPN fails to set default gateway over PPP (PPTP, L2TP/IPsec, 3G)

If you are running a PPP-based connection (can be another VPN like PPTP, L2TP/IPsec or just a Mobile connection) and you try to connect using OpenVPN, it will connect but won't set the default gateway. This is the error message OpenVPN generates:

NOTE: unable to redirect default gateway -- Cannot read current default gateway from system

The issue is caused by the PPP daemon which doesn't set the default gateway via IP but via link ID. Running netstat -rn|grep ppp0:

default            link#6             UCS             1        0    ppp0
default            192.168.2.1        UGScI           1        0     en0

Notice the link#6 instead of gateway IP address. OpenVPN tries to read the default gateway in IP address format, so it fails to read it if it's set like in the example above.

To fix it, you need to instruct ppp to setup the gateway using the IP address instead of that link ID.

Create a ppp start-up script /etc/ppp/ip-up and add the following:

#!/bin/sh
PATH=/sbin:/usr/sbin/:/usr/bin:/bin
gw=`ifconfig ppp0|grep inet| awk '{ print $4 }'`
route change default $gw -ifscope ppp0

Save the script and make it executable running chmod a+x /etc/ppp/ip-up

Now connect again using the ppp-based VPN or mobile connection and run netstat -rn|grep default. You should no longer see the link# ID as default gateway. OpenVPN should be able to read the default gateway correctly now and connect successfully.

Please note that the above script was made for interface ppp0. If for any reason you have more/other, make the changes accordingly.


Other tutorials: