I'm using network-manager-openvpn (w Ubuntu 14.04) to manage VPN connections (client end).

I need to run a script when a VPN is activated to fix some routing issues. I know how to do this using openvpn config options ( --script-security 2 --up /script.. ) but I can not figure out a sensible way with network-manager in the mix.

Is there a "recommended" way to approach this without reverting to pre-network-manager config files?

Or is there a suggested way to detect that the VPN has come up and hence triggering an action (something a bit more elegant than firing off a cron to look at the status every minute would be appreciated!)?

share|improve this question

Add your script to /etc/network/if-up.d/ directory.

All the scripts in this directory will run when a connection or vpn connection starts (up|vpn-up).

As noted here network-manager-openvpn does not provide such functionality, you otherwise have to use openvpn directly.

Because this directory load scripts on connection and vpn connection, your script may require additional checks.

Take a look at the file /etc/NetworkManager/dispatcher.d/01ifupdown. You can see the which directories are used when connection changes.

I use the /etc/network/if-post-down.d/ directory with a script to disconnect in the event my vpn connection fails.

Hope this helps, cheers.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.