You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MagicDNS domains don't get registered as expected in WSL /etc/resolv.conf #775
Install WSL1 (Windows Subsystem for Linux, version 1. I haven't tested version 2 but I suspect it might be the same)
Enable MagicDNS
From the cmd.exe prompt, try ping <node1> (a valid nodename in MagicDNS)
Notice that the lookup works as expected
Enter a WSL1 console
Try ping <node1>
Expected:
The name lookup works like it did in cmd.exe
Actual:
No such hostname
In /etc/resolv.conf, I found this:
# This file was automatically generated by WSL. To stop automatic generation of
this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver <my router's DNS server>
nameserver 100.100.100.100
nameserver fec0:0:0:ffff::1
search <my router's DNS domain> <the first search domain set in the tailscale admin panel> ts.tailscale.com
The search list should also contain the MagicDNS domain. Adding it by hand makes the name lookup work, but slowly.
The <my router's DNS server> entry also should not be present. Commenting it out fixes the slowness. If that's not possible, another option might be to have the global tailscale.net domain respond with NS records pointing at 100.100.100.100 I guess? But that wouldn't work well for non-tailscale.net magicdns domains that we want to support eventually.
Unfortunately that doesn't work any more now we do split DNS using the OS API. If we want to fix this WSL2 bug, and I think we do, then we should consider going back to setting the OS blanket DNS to 100.100.100.100 and implementing the OS DNS settings there ourselves.
As far as I know, WSLs dns handling is so broken that it will be wrong no
matter what we register with windows. Complaints in this bug pre-date split
dns.
The only friendly solution is likely to be intrusively poking around in WSL
ourselves from outside the container.
If we go back to setting the Windows host OS DNS to 100.100.100.100, the patch I linked to fixes WSL2. (Probably WSL1 too.) The problem is we gave up our global OS hook with split DNS, instead we started telling the OS how to cleverly avoid us, and WSL{,2} completely ignores the clever OS settings.
Hmm, maybe WSL2 works differently from WSL1 then. Because I’m saying the
opposite: we only recently started being fancy but at least WSL1 never
worked quite right without me manually overriding resolv.conf.
I can’t remember, maybe it did set quad-100 but it didn’t set search paths,
which is still not enough. Maybe WSL2 does it right though.
On Sat, Jun 12, 2021 at 12:02 David Crawshaw ***@***.***> wrote:
That's exactly what I described.
If we go back to setting the Windows host OS DNS to 100.100.100.100, the
patch I linked to fixes WSL2. (Probably WSL1 too.) The problem is we gave
up our global OS hook with split DNS, instead we started telling the OS how
to cleverly avoid us, and WSL{,2} completely ignores the clever OS settings.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#775 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAFA4E3UJSFNOVLQECRJQ3TSOAKZANCNFSM4RVJZTDQ>
.
We only recently started being fancy, but we never had the commit I linked to above.
In the past we relied on the OS to set search path prefixes, which WSL does not inherit from the host windows OS. What I changed is you can now directly dig <shortname> @100.100.100.100 and it internally appends the MagicDNS suffix for domains that have only one component. It's a bit of a hack, but one I think with some work we can make reliable.
Oh, I see. I didn't realize that was on the table (or that resolvers would even work with it). Although now that I'm thinking of it, now I'm having deja vu that maybe we used to do that in Nitix.
It's quite possibly a major DNS spec violation, so we might want to look carefully. For example, what should happen if we have a one-element hostname that overlaps with a TLD?
If it works though and we can figure out the edge cases, this might be approach I can get behind.
The philosophical reason: this is violating what a DNS resolver is required to do. When we receive a DNS question for the FQDN foo., we are not at liberty to interpret that as "maybe you meant foo plus whatever I feel like". We are required to respond to the question as phrased, and the correct response is NXDOMAIN.
systemd-resolved would appear to do this, but it does not. It only does search path expansion and other single-label special treatment (e.g. delegation to LLMNR) when queried through non-DNS APIs where it is expected to do that work. It does not do this when queried through 127.0.0.53.
Doing this breaks dnssec validation, because the record contents and associated names no longer match. We'd have to implement dnssec validation in quad-100 to work around that, and, um, please, no.
Reconfiguring the resolver in this way still results in incorrect behavior in WSL, because quad-100 doesn't apply the split-DNS policies configured within Windows. We'll end up with WSL having access to a subset of the DNS resolutions available to its host, which will just lead to more bug reports. Right now, we're broken in WSL exactly as much as other Windows DNS facilities are.
We already have a viable workaround for WSL users, which is to override resolv.conf and point it manually to quad-100 with their desired configuration. Given that we already have an option that has users explicitly acknowledge the shortcomings of WSL, I'd rather not make too many compromises on correctness in the pursuit of another fix.
Trying to mangle the host's configuration in the hopes that WSL will happen to extract some random subset of the configuration that happens to work is not a viable option, IMO. The evolution of how WSL configures DNS over time tells me that we'll forever be chasing the latest change, trying to trick it into installing the right config.
To make this work right, we need to either have the host tailscaled be aware of WSL containers and manage their DNS config itself (in which case we can set up something similar to exit node DNS routing, and make WSL DNS fully work the way it should), or have Microsoft fix their operating system. Neither of these are very satisfying options, but I would rather have WSL remain "broken due to OS limitations, with a known workaround" than implement this hack.
I took at a look at how DNS works on windows and it looks like implementing a stub resolver is gluing registry keys together. I'll give it a try tomorrow.
Alternatively to quad100+1: can we identify that requests are coming from a WSL container? Combined with patching the container's resolv.conf to point at quad-100 (which already tries to adopt a mostly-correct configuration even in split-DNS mode, as a WSL workaround), I think I'm more okay implementing what you suggested if it's limited to just WSL - so we can keep the sadness limited to just WSL, at least.
Indeed that may be possible because of the vEth that WSL uses. I’ll investigate that.
One nice thing about quad100+1 is that while it’s a hack, it’s a consistent cross-platform hack, so it may be better to go that way. A particularly easy impl I’m going to try: do the magicdns single element host check, and if it’s not, forward to quad100.
Note that quad100 doesn't have the full split-DNS config from windows (stuff potentially added by Active Directory admins), because currently we assume that Windows will have peeled those off before sending to us. So, forwarding to quad100 won't get you exactly the behavior of resolving the name on Windows - though it'll probably get you something close enough for non-enterprise users.
It would be reasonably easy to extract all search domains from the registry. Perhaps quad100+1 should be: forward to quad100, trying every OS search domain?
So, the bit that's missing from quad100 isn't that, rather it's the NRPT (Name Resolution Policy Table) rules that admins can install. They're how Windows implements split-DNS at the OS level, and it supports more stuff than merely "use this different DNS resolver for this domain". It also has a whole host of stuff related to access to remote device management infrastructure over some kind of whacky auto-IPSec based thing that ships in Windows, which is allegedly popular with enterprise Windows admins - think BeyondCorp but only works for device management stuff. AFAICT, we can't simply extract those rules and do something reasonable with them in quad-100, they only kick in and work if we ask the OS to resolve names for us.
So, to get 100% the same behavior inside WSL as outside, the plumbing we need is to have something like quad100+1, but it delegates to whatever win32 name resolution API exists, which would correctly hook up all this NRPT nonsense and give correct answers.
Alternatively, if we forward to quad100 and do as you suggest, filling out each search path in order - that works, but means WSL containers will only get acces to the "default" resolver + MagicDNS, not the full Windows DNS configuration. With a bunch of extra work, we could extract the NRPT rules that only deal with normal DNS resolvers, and install those as split-DNS configs in quad100, but we'd still be missing the more advanced NRPT rules that we can't reimplement without being the OS.
Well that points at what I started doing, which is implement a stub resolver directly on the go resolver. Unfortunately the opinionated high level api of the net package makes it hard to map values back properly. I’ll dig into what actual win32 calls happen underneath.
Yeah, the net package resolver isn't well suited to the subtle things we're trying to do.
To get off the ground, pointing statically at today's quad-100 and populating search paths in resolv.conf from outside WSL would get us roughly "the not-quite-right thing WSL did before, plus MagicDNS". Maybe that's enough and I'm wrong about folks then blaming us for the remaining long-tail things not working.
changed the title [-]MagicDNS domains don't get registered as expected in WSL1 /etc/resolv.conf[/-][+]MagicDNS domains don't get registered as expected in WSL /etc/resolv.conf[/+]on Sep 9, 2021
Activity
chancecarey commentedon Mar 22, 2021
Same issue with WSL2.
crawshaw commentedon Jun 12, 2021
I attempted the "obvious" fix for this in https://github.com/tailscale/tailscale/tree/crawshaw/magicdnsalways, making 100.100.100.100 resolve shortened magicdns names directly without the OS having to add a search prefix.
Unfortunately that doesn't work any more now we do split DNS using the OS API. If we want to fix this WSL2 bug, and I think we do, then we should consider going back to setting the OS blanket DNS to 100.100.100.100 and implementing the OS DNS settings there ourselves.
crawshaw commentedon Jun 12, 2021
(cc @danderson)
apenwarr commentedon Jun 12, 2021
crawshaw commentedon Jun 12, 2021
That's exactly what I described.
If we go back to setting the Windows host OS DNS to 100.100.100.100, the patch I linked to fixes WSL2. (Probably WSL1 too.) The problem is we gave up our global OS hook with split DNS, instead we started telling the OS how to cleverly avoid us, and WSL{,2} completely ignores the clever OS settings.
apenwarr commentedon Jun 12, 2021
crawshaw commentedon Jun 12, 2021
We only recently started being fancy, but we never had the commit I linked to above.
In the past we relied on the OS to set search path prefixes, which WSL does not inherit from the host windows OS. What I changed is you can now directly
dig <shortname> @100.100.100.100and it internally appends the MagicDNS suffix for domains that have only one component. It's a bit of a hack, but one I think with some work we can make reliable.apenwarr commentedon Jun 12, 2021
Oh, I see. I didn't realize that was on the table (or that resolvers would even work with it). Although now that I'm thinking of it, now I'm having deja vu that maybe we used to do that in Nitix.
It's quite possibly a major DNS spec violation, so we might want to look carefully. For example, what should happen if we have a one-element hostname that overlaps with a TLD?
If it works though and we can figure out the edge cases, this might be approach I can get behind.
cc: @danderson for the voice of realism :)
mnordhoff commentedon Jun 12, 2021
DNSMasq and IIRC systemd-resolved support doing the same thing. So it has precedent and, presumably, doesn't cause massive problems for most users.
(I'm a DNS purist and it makes me uncomfortable, but I'm not gonna complain.)
danderson commentedon Jun 13, 2021
I'm uncomfortable doing this.
foo., we are not at liberty to interpret that as "maybe you meantfooplus whatever I feel like". We are required to respond to the question as phrased, and the correct response is NXDOMAIN.Trying to mangle the host's configuration in the hopes that WSL will happen to extract some random subset of the configuration that happens to work is not a viable option, IMO. The evolution of how WSL configures DNS over time tells me that we'll forever be chasing the latest change, trying to trick it into installing the right config.
To make this work right, we need to either have the host tailscaled be aware of WSL containers and manage their DNS config itself (in which case we can set up something similar to exit node DNS routing, and make WSL DNS fully work the way it should), or have Microsoft fix their operating system. Neither of these are very satisfying options, but I would rather have WSL remain "broken due to OS limitations, with a known workaround" than implement this hack.
2 remaining items
crawshaw commentedon Jun 13, 2021
I took at a look at how DNS works on windows and it looks like implementing a stub resolver is gluing registry keys together. I'll give it a try tomorrow.
danderson commentedon Jun 13, 2021
Alternatively to quad100+1: can we identify that requests are coming from a WSL container? Combined with patching the container's resolv.conf to point at quad-100 (which already tries to adopt a mostly-correct configuration even in split-DNS mode, as a WSL workaround), I think I'm more okay implementing what you suggested if it's limited to just WSL - so we can keep the sadness limited to just WSL, at least.
crawshaw commentedon Jun 13, 2021
Indeed that may be possible because of the vEth that WSL uses. I’ll investigate that.
One nice thing about quad100+1 is that while it’s a hack, it’s a consistent cross-platform hack, so it may be better to go that way. A particularly easy impl I’m going to try: do the magicdns single element host check, and if it’s not, forward to quad100.
danderson commentedon Jun 13, 2021
Note that quad100 doesn't have the full split-DNS config from windows (stuff potentially added by Active Directory admins), because currently we assume that Windows will have peeled those off before sending to us. So, forwarding to quad100 won't get you exactly the behavior of resolving the name on Windows - though it'll probably get you something close enough for non-enterprise users.
crawshaw commentedon Jun 13, 2021
It would be reasonably easy to extract all search domains from the registry. Perhaps quad100+1 should be: forward to quad100, trying every OS search domain?
danderson commentedon Jun 13, 2021
So, the bit that's missing from quad100 isn't that, rather it's the NRPT (Name Resolution Policy Table) rules that admins can install. They're how Windows implements split-DNS at the OS level, and it supports more stuff than merely "use this different DNS resolver for this domain". It also has a whole host of stuff related to access to remote device management infrastructure over some kind of whacky auto-IPSec based thing that ships in Windows, which is allegedly popular with enterprise Windows admins - think BeyondCorp but only works for device management stuff. AFAICT, we can't simply extract those rules and do something reasonable with them in quad-100, they only kick in and work if we ask the OS to resolve names for us.
So, to get 100% the same behavior inside WSL as outside, the plumbing we need is to have something like quad100+1, but it delegates to whatever win32 name resolution API exists, which would correctly hook up all this NRPT nonsense and give correct answers.
Alternatively, if we forward to quad100 and do as you suggest, filling out each search path in order - that works, but means WSL containers will only get acces to the "default" resolver + MagicDNS, not the full Windows DNS configuration. With a bunch of extra work, we could extract the NRPT rules that only deal with normal DNS resolvers, and install those as split-DNS configs in quad100, but we'd still be missing the more advanced NRPT rules that we can't reimplement without being the OS.
crawshaw commentedon Jun 13, 2021
Well that points at what I started doing, which is implement a stub resolver directly on the go resolver. Unfortunately the opinionated high level api of the net package makes it hard to map values back properly. I’ll dig into what actual win32 calls happen underneath.
danderson commentedon Jun 13, 2021
Yeah, the net package resolver isn't well suited to the subtle things we're trying to do.
To get off the ground, pointing statically at today's quad-100 and populating search paths in resolv.conf from outside WSL would get us roughly "the not-quite-right thing WSL did before, plus MagicDNS". Maybe that's enough and I'm wrong about folks then blaming us for the remaining long-tail things not working.
net/dns: set WSL /etc/resolv.conf
net/dns: set WSL /etc/resolv.conf
net/dns: set WSL /etc/resolv.conf
net/dns: set WSL /etc/resolv.conf
net/dns: set WSL /etc/resolv.conf
[-]MagicDNS domains don't get registered as expected in WSL1 /etc/resolv.conf[/-][+]MagicDNS domains don't get registered as expected in WSL /etc/resolv.conf[/+]