Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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>
share|improve this question
1  
This looks like a duplicate of askubuntu.com/questions/190899/… –  msbrown Dec 20 '13 at 15:30
    
Yes, it looks so. And the answer there worked for me. Instead of opening the Network Manager, open System Settings -> Network. Multiple VPNs can be checked ON. –  Ferdinand Prantl May 31 at 11:44

1 Answer 1

up vote 1 down vote accepted
+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

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.