Automatically dis/reconnect on network interface change?

Hi Andreas,

It sounds like you’re using a UDP connection with the default ping/ping-restart values. OpenVPN defaults to a ping value of 10 seconds, and a ping-restart value of 60 seconds (although it’s not uncommon for this to be set to 120 in template configurations). UDP connections are completely reliant on pings to determine when the connection is no longer active. OpenVPN pings are not real ICMP pings: they take place as part of the OpenVPN control channel as part of the connection.

As a test, try setting the ping value to 2, and the ping-restart value to 10. This should allow OpenVPN to detect that the connection is no longer active after 10 seconds and trigger a restart. Also ensure that the server isn’t pushing any ping/keepalive values that may override these settings.

However please be aware that by default OpenVPN will attempt to keep the VPN interface, routes, etc. in place during a connection restart, which is probably not the behaviour you are after. To stop this, make sure all of the “persist” options are un-ticked for your connection (under the Options tab when editing your connection in Viscosity) and that the server isn’t pushing any of these options either.

You could also consider a move to TCP. While TCP has lower performance, it will detect the drop-out near instantly.

As a final option, you could also consider having an AppleScript that runs on a network change and disconnects/reconnects the connection. See the following forum post for how this could be achieved:
https://www.sparklabs.com/forum/t/auto-connect-vpn-on-specific-network/840/2

Cheers,
James