[PATCH] wg-quick hatchet: Support systemd-resolved split-dns setup

Dominik Heidler dheidler at suse.de
Fri Feb 18 11:55:57 UTC 2022


---
 contrib/dns-hatchet/hatchet.bash | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/contrib/dns-hatchet/hatchet.bash b/contrib/dns-hatchet/hatchet.bash
index bc4d090..30eb25b 100644
--- a/contrib/dns-hatchet/hatchet.bash
+++ b/contrib/dns-hatchet/hatchet.bash
@@ -5,7 +5,8 @@ set_dns() {
                { printf 'nameserver %s\n' "${DNS[@]}"
                  [[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
                } | cmd resolvconf -a "$INTERFACE" -m 0 -x
-       else
+       # Don't ruin a proper split dns setup
+       elif [[ "$(readlink /etc/resolv.conf)" != "/run/systemd/resolve/stub-resolv.conf" ]] ; then
                echo "[#] mount \`${DNS[*]}' /etc/resolv.conf" >&2
                [[ -e /etc/resolv.conf ]] || touch /etc/resolv.conf
                { cat <<-_EOF
@@ -30,6 +31,15 @@ set_dns() {
                _EOF
                )"
        fi
+       # If systemd-resolved is installed, set the dns configuration there (as well).
+       # It might be used additionally (eg for containers) or even for the whole system.
+       # A teardown is not really needed as resolvectl detects the interface disappearing.
+       if resolvectl status >/dev/null 2>&1 ; then
+               cmd resolvectl dns "$INTERFACE" "${DNS[@]}"
+               # Prefix each domain with '~' which will tell resolvectl to use that domain
+               # for dns routing but not as a search domain
+               cmd resolvectl domain "$INTERFACE" "${DNS_SEARCH[*]/#/\~}"
+       fi
        HAVE_SET_DNS=1
 }
 
-- 
2.35.1


More information about the WireGuard mailing list