Skip to content

Instantly share code, notes, and snippets.

@nonkronk
Last active April 2, 2023 20:14
Show Gist options
  • Save nonkronk/ff64e98cf42492c2e8c5bc543cc08862 to your computer and use it in GitHub Desktop.
Save nonkronk/ff64e98cf42492c2e8c5bc543cc08862 to your computer and use it in GitHub Desktop.
Auto-resolve all Wireguard endpoints (Dynamic DNS / IP address)

Auto-resolve all Wireguard endpoints (Dynamic DNS / IP address)

Add a systemd timer to run the script every 30 seconds:

sudo vi /etc/systemd/system/wg-autoresolve.timer
[Unit]
Description=Periodically auto-resolve DNS of all WireGuard endpoints

[Timer]
OnCalendar=*:*:0/30

[Install]
WantedBy=timers.target

Add a systemd service to run the script:

sudo vi /etc/systemd/system/wg-autoresolve.service
[Unit]
Description=Auto-resolve DNS of all WireGuard endpoints
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'for i in /etc/wireguard/*.conf; do /usr/share/doc/wireguard-tools/examples/reresolve-dns/reresolve-dns.sh "$i"; done'

Enable & start the timer:

sudo systemctl enable wg-autoresolve.timer
sudo systemctl start wg-autoresolve.timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment