6

What is the easiest way to detect that a vpnc connection on Linux/Ubuntu has disconnected?

Manually, I think the way to detect is to check whether the interface (tun0) appears in /sbin/ifconfig output. Is there a better way to find out immediately, so that a script can be run to restart the connection?

  • 1
    How often does the VPN disconnect? and you need to find out why if it is more than once every few hours. – Joshua Nurczyk Sep 13 '09 at 18:21
  • some vpn servers/clients can be configured to disconnect after a certain period of inactivity. this is something the IT staff would configure. – quack quixote Oct 11 '09 at 21:27
  • I've hit this, too. Are you using vpnc-connect/vpnc-disconnect by any chance? – TREE Oct 15 '09 at 20:45
4

The script /etc/vpnc/vpnc-script is called on various events, including connect and disconnect.

This sounds like you are using ubuntu or debian. If you are, the scripts

/etc/vpnc/vpnc-script-disconnect-action

and

/etc/vpnc/vpnc-script-post-disconnect-action

are called for the relevant events. You can create those files if they don't exist, and put whatever logic you want in there.

If you aren't using a debian-based distribution with these sub-scripts, you can modify /etc/vpnc/vpnc-script directly to add whatever logic you want.

If you are going to have logic to call vpnc-connect again, I recommend disconnecting that from the disconnect script somehow so you don't end up in an infinite loop.

| improve this answer | |
3

I use a cron to take care of it so I can easily change it without having to remember what script I edited. The cron job is below.

*/15 * * * * [[ -d /sys/devices/virtual/net/tun0 ]] || /usr/sbin/vpnc /etc/vpnc/yourconf.conf

| improve this answer | |
1

Typically the VPN connection should not break so frequently. In your case, you can first try to diagnose the real connectivity issue instead of writing scripts to automatically connect to the vpn when disconnected.

| improve this answer | |
-2

The below worked for me:

/sbin/ifconfig | /bin/grep -q tun0 || sudo /usr/sbin/vpnc-connect

| improve this answer | |

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.