9

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!)?

6

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.

1
  • 1
    Bump this subject because I have same problem.. When OpenVPN call the "up" script, it gives some dynamic arguments ; how to get them in [...]/if-up.d/my-custom-script ? – Doubidou Sep 27 '18 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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