DNS server inside wsl2 is not working for windows #4592
Replies: 14 comments
-
Is curl running in WSL? The prompt text suggests its Command Prompt. |
Beta Was this translation helpful? Give feedback.
-
No, both of the commands are running in windows terminal.
Also |
Beta Was this translation helpful? Give feedback.
-
I have been trying to get DnsMasq working in WSL2 as well. dnsmaq is running on the guest system and can resolve names just fine but I can't figure out how to make windows able to access that information. Setting 127.0.0.1 as the dns server for my network adapter doesn't work and using the ip address of the guest doesn't work but instead of just not working it times out. It would be an incredible tool to have dnsmasq work for windows. |
Beta Was this translation helpful? Give feedback.
-
I have done experiments with a few different setups, none of which work. In WSL I have dnsmasq service running and listening on addresses (0.0.0.0). I can use nslookup in bash to query all dns records for my local addresses like *.test and I get:
Now moving into windows without modifying the network adapter and using nslookup
It can also resolve internet addresses
Now if I modify the network adapter to point to 172.24.81.0 for dns, you would think that would work. However, Windows instead reports it has no internet and does not resolve any addresses. There has to be a way to make it work. My theory is that it causing an endless loop. |
Beta Was this translation helpful? Give feedback.
-
On my case, Here is my temporary solution:
Here is my hosts file
Here is my scripts
And my windows task action
|
Beta Was this translation helpful? Give feedback.
-
That does not provide the ability to have wildcard domains inside windows. With dnsmasq I can configure *.tld to resolve to localhost. Windows host file is very limited and dnsmasq could replace it's archaic system and make windows development more than just an experiment. I maintain Valet for WSL and dnsmasq is the final piece I need for development to be viable with WSL. The only other option is using acrylic dns proxy in windows. The native dnsmasq works way better for Valet. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to make this happen as well. I bought a Surface recently, and almost wish I'd have bought a MacBook Pro, but I'm hopeful WSL 2 will make Windows development less of a pain. The following are my configurations, tests, and findings. There seems to be a loop, and I've been trying various things with configurations that I may have tunnel vision and can't see if I'm missing something simple. Ethernet Adapter:
/etc/resolve.conf:
/etc/dnsmasq.conf:
In the following images Ethernet 2 is network adapter, vEthernet WSL, *any is from any iface in linux distro nslookup google.com (from WSL distro):
nslookup example.test (from WSL distro):
nslookup google.com (from Windows):
nslookup example.test yields the same result as google.com from windows. nslookup google.com 172.18.209.28 (from Windows using eth0 iface):
nslookup example.test 172.18.209.28 (from Windows using eth0 iface):
Using IPv6 iface address in place of the last IPv4 yields the same results. |
Beta Was this translation helpful? Give feedback.
-
I am having a very similar issue but just running dnsmasq inside an Alpine Linux Hyper-V VM. My workaround for now has been to use Acrylic to forward all queries to the dnsmasq server. It works but obviously isn't ideal. When ever I reconfigure my network interface(s) to talk directly to the dnsmasq server then name resolution fails. |
Beta Was this translation helpful? Give feedback.
-
The recent update with WSL2 broke this for me. Previously I've been using Acrylic proxy for a "wildcard" alternative to hosts file, and now it seems like there is literally no way of doing that on windows. It's incredibly frustrating because I'm developing a proxy and this functionality is essential. |
Beta Was this translation helpful? Give feedback.
-
I managed to get it working just now. I'm using Debian.
It works! :) Update. Domain resolution became insanely slow so as a workaround I added upstream servers to my dnsmasq configuration:
That did the trick. Update 2. It didn't. After a reboot it's still working but DNS resolution is slow again. Like many several seconds slow. Update 3. I set my preferred DNS in my primary network interface on Windows and followed these steps to change interface binding order and it seems to have corrected the issue of slow DNS resolution. Before, running a nslookup to |
Beta Was this translation helpful? Give feedback.
-
Also trying to set up dnsmasq to handle *.test domains internally. Here' what I've done (Ubuntu 20.04):
At this point if I run dig facebook.com +short
157.240.14.35
dig example.test +short
127.0.0.1 Sadly in Windows land |
Beta Was this translation helpful? Give feedback.
-
I did the exactly same steps with you and got the same result. |
Beta Was this translation helpful? Give feedback.
-
Don't set the DNS of your main network. Set the DNS of your WSL network with the IP of your Linux VM. That's what did the trick for me. I also had to set a DNS in my main network but this time pointed to your preferred DNS service, like Google or CloudFlare. |
Beta Was this translation helpful? Give feedback.
-
This issue had no repro, but the spirit was answered well by @haggen above. Whether bouncing every DNS query in Windows off a WSL instance is a good idea can be left to the beholder. Having more than one thing listening on port For an alternate approach to accomplishing a similar end result, some people may want to consider |
Beta Was this translation helpful? Give feedback.
-
I just installed a dnsmasq inside wsl2, and bind the windows' dns to its address, and I just found that the nslookup is working well but ping and curl is not working.
What should I do to fix it?
Here is the command and its result:
Beta Was this translation helpful? Give feedback.
All reactions