Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Dominik Heidler <dheidler@suse.de>
To: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: [PATCH] wg-quick hatchet: Support systemd-resolved split-dns setup
Date: Fri, 18 Feb 2022 12:55:57 +0100	[thread overview]
Message-ID: <d98464e9-d16c-78fa-d3f3-f05ad603890a@suse.de> (raw)


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

                 reply	other threads:[~2022-02-18 12:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d98464e9-d16c-78fa-d3f3-f05ad603890a@suse.de \
    --to=dheidler@suse.de \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).