Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] wg-quick hatchet: Support systemd-resolved split-dns setup
@ 2022-02-18 11:55 Dominik Heidler
  0 siblings, 0 replies; only message in thread
From: Dominik Heidler @ 2022-02-18 11:55 UTC (permalink / raw)
  To: WireGuard mailing list


---
 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-18 12:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-18 11:55 [PATCH] wg-quick hatchet: Support systemd-resolved split-dns setup Dominik Heidler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).