Last active
August 16, 2023 02:50
-
-
Save utarn/41e86c28e83fe990fe9108106dd2006a to your computer and use it in GitHub Desktop.
Systemd Wireguard auto re-resolve DNS for dynamic DNS wireguard server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected] | |
# 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