WSL2 DNS issues
-
Your Windows build number:
Microsoft Windows [Version 10.0.19041.264] (desktop) Microsoft Windows [Version 10.0.19041.264] (laptop) -
What you're doing and what's happening: on wsl2 on my desktop PC, name resolution seems to always fail (i've had it working in the past) on my laptop, wsl2 name resolution works fine on my desktop:
sudo apt-get updateErr:1 http://archive.ubuntu.com/ubuntu focal InRelease Temporary failure resolving 'archive.ubuntu.com' Err:2 http://security.ubuntu.com/ubuntu focal-security InRelease Temporary failure resolving 'security.ubuntu.com' Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease Temporary failure resolving 'archive.ubuntu.com' Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease Temporary failure resolving 'archive.ubuntu.com' Reading package lists... Done W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease Temporary failure resolving 'security.ubuntu.com' W: Some index files failed to download. They have been ignored, or old ones used instead.ping -c 4 google.comping: google.com: Temporary failure in name resolutionping -c 4 172.217.23.174(the ip i get fromping google.comin cmd)PING 172.217.23.174 (172.217.23.174) 56(84) bytes of data. 64 bytes from 172.217.23.174: icmp_seq=1 ttl=54 time=10.9 ms 64 bytes from 172.217.23.174: icmp_seq=2 ttl=54 time=9.72 ms 64 bytes from 172.217.23.174: icmp_seq=3 ttl=54 time=8.60 ms 64 bytes from 172.217.23.174: icmp_seq=4 ttl=54 time=7.85 ms --- 172.217.23.174 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3006ms rtt min/avg/max/mdev = 7.850/9.260/10.865/1.141 ms
-
What's wrong / what should be happening instead: on my laptop:
sudo apt-get updateHit:1 http://archive.ubuntu.com/ubuntu bionic InRelease Get:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB] Get:3 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB] Hit:4 http://download.mono-project.com/repo/debian wheezy InRelease Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Hit:6 https://dl.yarnpkg.com/debian stable InRelease Hit:7 https://download.jitsi.org stable/ InRelease Get:8 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [948 kB] Get:9 http://archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [322 kB] Get:10 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [724 kB] Get:11 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [55.3 kB] Get:12 http://archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [13.8 kB] Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1075 kB] Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [334 kB] Get:15 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [229 kB] Get:16 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [45.7 kB] Get:17 http://security.ubuntu.com/ubuntu bionic-security/restricted Translation-en [11.4 kB] Get:18 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [666 kB] Get:19 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [221 kB] Get:20 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [7596 B] Get:21 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [2824 B] Fetched 4909 kB in 4s (1389 kB/s) Reading package lists... Doneping -c 4 google.comPING google.com (172.217.23.174) 56(84) bytes of data. 64 bytes from fra15s22-in-f14.1e100.net (172.217.23.174): icmp_seq=1 ttl=54 time=10.1 ms 64 bytes from fra15s22-in-f14.1e100.net (172.217.23.174): icmp_seq=2 ttl=54 time=9.69 ms 64 bytes from fra15s22-in-f14.1e100.net (172.217.23.174): icmp_seq=3 ttl=54 time=11.4 ms 64 bytes from fra15s22-in-f14.1e100.net (172.217.23.174): icmp_seq=4 ttl=54 time=8.50 ms --- google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3004ms rtt min/avg/max/mdev = 8.501/9.952/11.462/1.059 msping -c 4 172.217.23.174(the ip i get fromping google.comin cmd)PING 172.217.23.174 (172.217.23.174) 56(84) bytes of data. 64 bytes from 172.217.23.174: icmp_seq=1 ttl=54 time=10.6 ms 64 bytes from 172.217.23.174: icmp_seq=2 ttl=54 time=8.54 ms 64 bytes from 172.217.23.174: icmp_seq=3 ttl=54 time=9.20 ms 64 bytes from 172.217.23.174: icmp_seq=4 ttl=54 time=8.16 ms --- 172.217.23.174 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 8.163/9.133/10.620/0.935 ms
I am having the same issue.
editing the /etc/resolv.conf file, add
nameserver 1.1.1.1
and disable auto generation of the file in /etc/wsl.conf
editing the /etc/resolv.conf file, add
nameserver 1.1.1.1and disable auto generation of the file in /etc/wsl.conf
This didn't work for me.
editing the /etc/resolv.conf file, add
nameserver 1.1.1.1and disable auto generation of the file in /etc/wsl.conf
That doesn't work for me because i need to use my routers dns because i use that instead of using IPs
I made DNS work by disabling Windows firewall
I made DNS work by disabling Windows firewall
tried this too, but didn't work, that's not the problem
Yet another important issue with WSL 2 and no word from the team. I guess the best and most stable approach right now is to just use a full Linux distribution.
+1
+1
I'm having the same issue (not using a proxy, or vpn btw). After endless searching, none of the suggested workarounds (turning off firewall, manually overwriting the configuration files) found in other threads resolved the issue, so I had to revert do WSL 1..
It baffles me that an issue that impairs functionality to this degree has not been acknowledged, let alone fixed 2-3 months after "release".
editing the /etc/resolv.conf file, add
nameserver 1.1.1.1and disable auto generation of the file in /etc/wsl.confThis didn't work for me.
Then this is not your issue, you likely have a firewall issue or some other weird networking scenario like VPN clients mucking it up.
The auto populated IP in the resolv.conf should point to the virtual host adapter IP. This doesn't seem to do DNS resolution (at least it doesn't in the current insider builds), unclear if that is a bug or intentional (it is annoying).
On a fresh WSL install you should always be able to ping say 8.8.8.8 - if you can't ping you don't have a DNS issue you have a networking issue to track down.
I'm having the same issue (not using a proxy, or vpn btw). After endless searching, none of the suggested workarounds (turning off firewall, manually overwriting the configuration files) found in other threads resolved the issue, so I had to revert do WSL 1..
It baffles me that an issue that impairs functionality to this degree has not been acknowledged, let alone fixed 2-3 months after "release".
Sounds like you have an networking issue not a DNS issue - could you ping external IPs?
I'm having the same issue (not using a proxy, or vpn btw). After endless searching, none of the suggested workarounds (turning off firewall, manually overwriting the configuration files) found in other threads resolved the issue, so I had to revert do WSL 1.. It baffles me that an issue that impairs functionality to this degree has not been acknowledged, let alone fixed 2-3 months after "release".
Sounds like you have an networking issue not a DNS issue - could you ping external IPs?
The behaviour as follows.
In WSL 1 I can do the following:
- I can ping google.com (and get 216.58.214.206 back)
- I can ping the IP of google.com (so 216.58.214.206)
- I can curl google.com
In WSL 2 the results are as follows:
- I cannot ping google.com (ping: google.com: Temporary failure in name resolution)
- If I try to ping the IP directly I get something like: 4 packets transmitted, 0 received, 100% packet loss, time 3085ms
- I cannot curl google.com
Then this is not your issue
Incredibly unhelpful.
It is the issue for many people, it is the same in issue trackers/forums/etc across the internet.
The WSL instance cannot resolve domain names. Editing resolv.conf to point to a functioning nameserver "works" for the duration of the session, but as soon as the distro is rebooted resolv.conf is regenerated using WSL's original template. Because etc/resolv.conf is actually a symlink to run/resolvconf/resolv.conf
Steps that have worked for me:
- Boot your distro.
cd ~/../../etc- Create wsl.conf, however you see fit.
sudo vim wsl.conf,sudo touch wsl.confand edit it later, whatever. - Add these lines to wsl.conf:
[network]generateResolvConf=false exitor in Windows cmdwsl --terminate [YourDistroName]- Boot your distro.
At this point, thanks to wsl.conf, run/resolvconf should no longer exist and will never be created again.
cd ~/../../etcsudo rm resolv.conf- this deletes the existing symlink file.- Create a new resolv.conf, however you see fit.
sudo vim resolv.conf,sudo touch resolv.confand edit it later, whatever. - Add this line to resolv.conf:
nameserver 8.8.8.8replace 8.8.8.8 with your preferred functional nameserver. exitor in Windows cmdwsl --terminate [YourDistroName]wsl --shutdownjust to be sure that you've definitely killed everything.- Boot your distro.
- Confirm that your resolv.conf changes are still in effect, or just ping a domain name and cry tears of joy after struggling to get this working for far too fucking long.
Then this is not your issue
Incredibly unhelpful.
It is the issue for many people, it is the same in issue trackers/forums/etc across the internet.
The WSL instance cannot resolve domain names. Editing resolv.conf to point to a functioning nameserver "works" for the duration of the session, but as soon as the distro is rebooted resolv.conf is regenerated using WSL's original template. Because etc/resolv.conf is actually a symlink to run/resolvconf/resolv.conf
Steps that have worked for me:
- Boot your distro.
cd ~/../../etc- Create wsl.conf, however you see fit.
sudo vim wsl.conf,sudo touch wsl.confand edit it later, whatever.- Add these lines to wsl.conf:
[network]generateResolvConf=falseexitor in Windows cmdwsl --terminate [YourDistroName]- Boot your distro.
At this point, thanks to wsl.conf, run/resolvconf should no longer exist and will never be created again.
cd ~/../../etcsudo rm resolv.conf- this deletes the existing symlink file.- Create a new resolv.conf, however you see fit.
sudo vim resolv.conf,sudo touch resolv.confand edit it later, whatever.- Add this line to resolv.conf:
nameserver 8.8.8.8replace 8.8.8.8 with your preferred functional nameserver.exitor in Windows cmdwsl --terminate [YourDistroName]wsl --shutdownjust to be sure that you've definitely killed everything.- Boot your distro.
- Confirm that your resolv.conf changes are still in effect, or just ping a domain name and cry tears of joy after struggling to get this working for far too fucking long.
This worked for me. Thank you so much! I still don't know why nobody is tackling this issue. insane...
As I said many folks don’t have a dns issue for example you had a networking issue by your own admission (100% packet loss). As I said one need to change DNS in the immediate post if pinging works. I asked the question to help identify the issue as there was little detail in the post to actually help. So 100% accurate and 100% helpful. Moreover the resolv.conf fix is posted many many times about wsl2..
Tip for folks on GitHub learn to identify what your issue is (networking) not what you think it is (dns).
I recently upgraded to 2004 and got access to WSL2. I installed a fresh version of Ubuntu 20.04 and experienced the same DNS issue reported by several others there. I am able to ping an external ip address (8.8.8.8), but not able to resolve a domain (github.com). This problem does not occur on WSL1.
As mentioned above, the workaround with changing the nameserver in resolv.conf is the only thing that resolves the issue.
@shoan you are totally correct. It seems WSL2 is assuming there is a dns resolver listening on the hosts internal network and there isn’t one listening (or isn’t accessible?).
Makes me wonder if this is actually a hyper-v networking bug rather than a WSL2 bug, aka hyper-v NAT should have a dns resolver listening. I have tried tweaking the WSL adapter to no avail. Next up more research on how and when the hyper-v does and doesn’t do dns resolution for guest VMs.
@shoan ok I think i know what might be causing the issue - it is some interaction of Hyper-V or Hyper-V plus docker desktop. I uninstalled docker desktop, i removed WSL and hyper-v and uninstalled the distros and re-installed this way on tis weeks insider build and name resolution works perfectly. My thesis is it is related to the restrictions mentioned here where only one NAT will work reliably - i noted my system had two vmswitches both with NAT..
re-Install procedure i used after cleaning out hyper-v and wsl and docker.
- uninstall all distros
- disable all of hyper-v component
- disable WSL component
- uninstall all TAP based networking by uninstalling two VPN clients i have installed (there are multiple issues logged with DNS issues in hyper-v NAT caused by installing VPNs that create TAP adapters)
- rebooted
- dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- reboot
- install debian from store
- run kernel update from here
Started debian, sudo ping 8.8.8.8 worked and apt-get upgrade worked perfectly
I will do more testing if i can now create a repro, without a reliable repro MS are not going to be able to troubleshoot this. Whatever the issue is it isn't WSL per-se - it is one of the other subsystems and its interaction with WSL.
This is what my WSL and Hyper-V looks like in add remove. Note Hyper-V appears as unistalled, next up seeing if checking things in the hyper-v component install breaks a working sceanrio.

this is what my network looks like - only one vswitch - and all is now working (i have had same issues as rest of you for months and months and months too - now i don't.... though today my PC also updated to 20180 so small chance that fixed it too!)

editing the /etc/resolv.conf file, add
nameserver 1.1.1.1and disable auto generation of the file in /etc/wsl.conf
This worked perfectly for me.
just not those nameservers
I added
nameserver router IP
and both google nameservers
had to create the wsl.conf file to stop the generation of the resolv.conf
Thanks!
It's a pity I need to find a work around, But I guess it is beta 🤷♂️