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