Wireguard connection not being restored

Ahoy friends.
Currently i use OpenWRT to establish a Wireguard Site-to-Site VPN to use my devices in my home network.
Unfortunately, sometimes the connections drops, and the Wireguard connection is not being restored, even if internet works.
Remote site is working, but OpenWRT shows something like "last handshake 1h ago".
So the VPN connection is not being restored automatically.
To resolve this issue, i have to restart my OpenWRT device (VPN Client).
How can i tell Wireguard to auto-reconnect, or restart the interface if this happens?

EDIT: The problem is the following.
The IP address of the remote network changes 2 times per day, and after that, the Wireguard connection can't be reestablished by the client.
How can i solve this problem on clientside (OpenWRT) to reconnect when the ip address of the peer changes?

1 Like

I've never personally run into an issue with my IP changing, but I'm going to guess that WireGuard performs a DNS lookup at the time of initialization, and then just uses the IP address from there -- it is probably not constantly resolving DNS.

Presumably you have a dynamic DNS service such that the remote network can be addressed by a domain name rather than purely IP. Hopefully it is picking up the new address relatively quickly. Assuming that both of these things are true, I think you'd want to make a script to do a DNS lookup against that domain name and compare it against the last known IP address. When it changes restart the wireguard interface so that the domain name is resolved again and it should reconnect successfully.

You add the wireguard_watchdog to your scheduled tasks. For a check every 15 minutes, use:

*/15 * * * * /usr/bin/wireguard_watchdog

1 Like

Note 1: For posterity: that script is contained in the "wireguard-tools" package
Note 2: You can schedule it every minute. In fact, you should, otherwise it may, obviously, take up to 15 minutes to recreate the connection. There is no harm in running it this frequently, the script brings virtually no memory or cpu overhead.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.