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?
1 Answers
The following modifications work well for multiple profiles:
- Add
Local Port 0to your .conf files in /etc/vpnc, if you haven't done so. This will use random local ports, and will allow multiple connections better. 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.shwith#!/bin/bash if ! nc -z -w 2 targetip targetport then /usr/sbin/vpnc-connect connectionprofile.conf fiChange the reconnect script
/etc/vpnc/reconnect-scriptto use all of thoseEnsureXXX.shscripts (do them one after another, so no&at the end)#!/bin/bash sleep 30 /usr/local/bin/EnsureVPN1XXX.sh /usr/local/bin/EnsureVPN2XXX.sh ...- The
/etc/init.d/vpncscript is almost the same, except you don't need to source/etc/default/vpncany 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.
- 714
- 1
- 8
- 13