4

I have to connect to two OpenVPN servers at once. How do I configure NetworkManager to connect as a client to both?

           -- <OpenVPN1> -- <Resource 1>
<laptop> -
           -- <OpenVPN2> -- <Resource 2>
2

1 Answer 1

5
+50

I think it is impossible using only Network Manager. But you can use a little trick:

First export your OpenVPN2 settings from Network Manager to some file, say ovpn2.conf.

Find your OpenVPN1 connection UUID:

nmcli con

Write script below, and put it under /etc/NetworkManager/dispatcher.d/, say two_vpn

#!/bin/sh
VPN_UUID=84d61cf6-6f51-4f84-93fb-df3c458db6d6
CONF_FILE=path/to/ovpn2.conf

interface=$1 status=$2
case $status in
  up|vpn-up)
      if [ $VPN_UUID == $CONNECTION_UUID ]; then
        # connect your second OpenVPN2 using .conf file:
        openvpn --config $CONF_FILE

      fi
    ;;
  down| vpn-down)
      if [ $VPN_UUID == $CONNECTION_UUID ]; then
        # close your second OpenVPN2
        pid=$(ps -ef | grep "[o]penvpn --config $CONF_FILE" | awk '{ print $2 }')
        kill $pid > /dev/null 2>&1
      fi
    ;;
esac

Don't forget to give chmod +x /etc/NetworkManager/dispatcher.d/two_vpn

That's it, now you only need to connect OpenVPN1, and OpenVPN2 will connect automatically. Also if you close OpenVPN1, OpenVPN2 will close.

Please let me know if something goes wrong, because I did not test script

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .