Skip to content

Instantly share code, notes, and snippets.

@utarn
Last active August 16, 2023 02:50
Show Gist options
  • Save utarn/41e86c28e83fe990fe9108106dd2006a to your computer and use it in GitHub Desktop.
Save utarn/41e86c28e83fe990fe9108106dd2006a to your computer and use it in GitHub Desktop.
Systemd Wireguard auto re-resolve DNS for dynamic DNS wireguard server
#!/bin/bash
# This script installs a systemd timer template named WireguardReResolveDNS.(service|timer)
# to run every 30 seconds. Requires that wireguard-tools is installed.
# Enable using e.g. systemctl enable --now wg-reresolve-dns@wg0.timer
# You need to do that separately for each wireguard interface
export NAME=wg-reresolve-dns@
cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
[Service]
Type=oneshot
ExecStart=/usr/share/doc/wireguard-tools/contrib/reresolve-dns/reresolve-dns.sh %i
EOF
cat >/etc/systemd/system/${NAME}.timer <<EOF
[Unit]
Description=${NAME} timer
[Timer]
Unit=${NAME}%i.service
OnCalendar=*-*-* *:*:00,10,20,30,40,50
Persistent=true
[Install]
WantedBy=timers.target
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment