Skip to content

How to use a PostUp hook to restart WireGuard every few minutes or hours? #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kevinfay opened this issue Sep 6, 2024 · 1 comment

Comments

@kevinfay
Copy link

kevinfay commented Sep 6, 2024

Dynamic IP addresses
Many users report having to restart WireGuard whenever a dynamic IP changes, as it only resolves hostnames on startup. To force WireGuard to re-resolve dynamic DNS Endpoint hostnames more often, you may want to use a PostUp hook to restart WireGuard every few minutes or hours.

https://github.com/pirate/wireguard-docs#dynamic-ip-addresses

"But I don't know how to implement this PostUp hook. Help me, pls.

@Gryd3
Copy link

Gryd3 commented May 22, 2025

Here's another resource for you to look into for dynamic DNS solutions : https://github.com/WireGuard/wireguard-tools/blob/master/contrib/reresolve-dns/reresolve-dns.sh

The idea is to use cron or systemd timers to run this every once in a while. There's no need to restart the tunnel, as it can be updated in place. This can be done manually if you intend the tunnel to run 24/7.

Some platforms don't support this, in which case you'll need to be creative in your solution. (eg, windows, RouterOS, Android...)
Automatic tunnel restarts are applicable to remote equipment that is inaccessible, or has no local-users that can toggle the tunnel or restart the device.

As for the PostUp hook itself.. you could just brute-force it:
= sleep 3600; systemctl restart [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants