I leave my raspberry with VPN connection on, and after several hours, I connect to it but has no internet connection. How to troubleshoot/diagnose?

All we need is an easy explanation of the problem, so here it is.

I connect my raspberry to VPN, and I leave it there for hours. When I check it connecting through SSH or VNC, I realize that it has not internet connection. If I reboot and then connect to VPN again it works again.

My question is: how to diagnose the problem? how to troubleshoot? Is there some log file or systemctl log that I can look into to find what cause the issue?

I want to automate that if the Pi is not connected to the internet then it reboots. I want to do that in a "clean" way via some .target file or udev rule.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You probably don’t need to reboot. Restarting the VPN connection when the rpi detects the outage should be good enough (unless it’s a hardware fault).

As for detecting the outage, is there some host or IP address that you know you should be able to reach when the VPN is up but not when the VPN is down? If so, set up a cron jobs that tries to fping that host. If it responds then all is OK. If not, restart the VPN.

Otherwise, if the VPN outage is noted in a log, write a script to monitor the log and restart the VPN when it goes down. e.g. via something beginning with:

tail -F /var/log/syslog |
  awk '/your outage message/ { system "/path/to/vpn-restart-script" }'

or write a perl script using the File::Tail module). BTW, File::Tail is in the libfile-tail-perl package on Debian, so should be available on Raspbian too.

If you can’t find an outage message in a log file and your VPN connection is started by a systemd service, you might be able to use systemctl status <servicename> to find out whether it’s up or not.

In short, there are two parts to solving this:

  1. Reliably detecting whether the VPN is up or not. This might require a cron job, or a script to run in the background monitoring a log file. It may require more than one test condition to detect the outage.

  2. Restarting the VPN connection if it isn’t. This is probably as simple as running systemctl restart servicename if the VPN is started with a systemd service. or /etc/init.d/vpn-service on SysV init. (these names aren’t exact, they’re just placeholders for whatever your real service names are).

These parts can (and should) be solved independently of each other.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply