Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Mark Knowles' Blog has a good explanation on how to maintain a persistent vpnc connection. However, this doesn't work well for multiple vpnc connections (Connecting doesn't work for me, everything gets reconnected on a single disconnect, ...). Is there a better way of maintaining multiple vpnc connections?

share|improve this question
add comment

1 Answer

The following modifications work well for multiple profiles:

  1. Add Local Port 0 to your .conf files in /etc/vpnc, if you haven't done so. This will use random local ports, and will allow multiple connections better.
  2. For every connection, pick an IP and port on the vpn network which you want to connect to (and maintain a connection to). For every connection, write a script in /usr/local/bin that checks the connection is still possible and if not launches vpnc, e.g. EnsureVPNXXX.sh with

    #!/bin/bash
    if ! nc -z -w 2 targetip targetport
    then /usr/sbin/vpnc-connect connectionprofile.conf
    fi
    
  3. Change the reconnect script /etc/vpnc/reconnect-script to use all of those EnsureXXX.sh scripts (do them one after another, so no & at the end)

    #!/bin/bash
    sleep 30
    /usr/local/bin/EnsureVPN1XXX.sh
    /usr/local/bin/EnsureVPN2XXX.sh
    ...
    
  4. The /etc/init.d/vpnc script is almost the same, except you don't need to source /etc/default/vpnc any longer

Don't forget that scripts need to be executable. As long as you call them from root, these scripts work very well in any automated cron-jobs, e.g. before you call scp or rdesktop on any box in the vpn network, just do a quite EnsureVPNxxx.sh. You can always drop back out of root with a su -u yourusername command. And use root's crontab, obviously.

share|improve this answer
add comment

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.