Openwrt vpn client (wireguard) how to make auto reconnect when vpn server ip address is changed?

My setup is,
At remote end, I have a raspberry pi running wireguard server. Since this ISP changes WAN ip address every 24 hours, I have a ddns update service running on the pi to automatically update the new ip to dns name every 5 minute.

At local, I have an openwrt router configured with wireguard client connected to above wireguard server.

Is there a way to make the VPN interface restart when dns ip is changed?

Presumably, your local side is acting as a client, right? In that case, use watchcat on your local side to detect when things stop working through the tunnel and then restart the Wireguard interface.

https://openwrt.org/docs/guide-user/advanced/watchcat

1 Like

Yes. my local side is acting as client.
watchcat should fix my problem I believe.

One question though, after ping fails on dns (at this point remote WAN IP is changed), it takes approximately 10 minutes for the remote raspberry pi to update new WAN ip to dns.
Is there a way, I can set that 10 min delay in watchcat restart interface?

I don't know, actually, as I've never used watchcat myself. But it seems that you should be able to set a period to properly account for this:
Restart Interface: the longest interval of time without a successful ping before the rule is activated

1 Like

There is also the WireGuard specific script to resolve the DNS of the endpoint:
From my notes:

if the only problem is that the DDNS address of the server is frequently changing you can run the built-in watchdog which periodically re-resolves the DNS address of the server by running as a cron job see:
https://openwrt.org/docs/guide-user/services/vpn/wireguard/extras#dynamic_address

And there is also a specific WireGuard watchdog script which can check every 10 sec if the above is not working:

But watchcat is also an excellent solution :slight_smile:

1 Like

Thank you for the details, I am yet to implement this.
If I have more questions, I shall get back here.

1 Like

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