WSL: WSL2 DNS stops working

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.18932.1000]

  • What you’re doing and what’s happening:
> bash
% host google.com
;; connection timed out; no servers could be reached
  • What’s wrong / what should be happening instead: DNS resolution should work

/etc/resolv.conf:

% cat /etc/resolv.conf
# 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 172.19.224.1

To my knowledge, I didn’t change anything. This has happened a few times, and rebooting fixes it. Sometimes just doing wsl --shutdown is sufficient to fix it. It correlates with my workstation going to sleep and resuming later with DNS in WSL2 not working.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 188
  • Comments: 297 (1 by maintainers)

Commits related to this issue

Most upvoted comments

My workaround:

  1. Create a file: /etc/wsl.conf.
  2. Put the following lines in the file
[network]
generateResolvConf = false
  1. In a cmd window, run wsl --shutdown
  2. Restart WSL2
  3. Create a file: /etc/resolv.conf. If it exists, replace existing one with this new file.
  4. Put the following lines in the file
nameserver 8.8.8.8
  1. Repeat step 3 and 4. You will see git working fine now.

For anyone seeing this, the “fixes” proposed are merely a workaround to the problem. In situations where internal/private DNS servers (eg. corporate or home network), DNS will not resolve as expected.

I consider this a critical bug.

My workaround:

  1. Create a file: /etc/wsl.conf.
  2. Put the following lines in the file
[network]
generateResolvConf = false
  1. In a cmd window, run wsl --shutdown
  2. Restart WSL2
  3. Create a file: /etc/resolv.conf. If it exists, replace existing one with this new file.
  4. Put the following lines in the file
nameserver 8.8.8.8
  1. Repeat step 3 and 4. You will see git working fine now.

wsl --shutdown doesn’t seem to work for me wslconfig.exe /terminate Ubuntu does

Hot take: Instead of running Windows with Linux VM in it, you can just run Linux with optional Windows VM in it if necessary. Solved all my problems.

3 Years and 0 replies from Microsoft, awesome! 🎉🎉🎉

@Klein-Hu : tried your workaround, followed your steps, but it doesn’t seem to be working for me.

My /etc/resolv.conf file is getting wiped out every time I relaunch wsl2 😕

I got a clue in the following: Issue 4844 (I also removed docker WSL but I don’t think that that made any diff)

  1. Created a /etc/wsl.conf containing

    [network]
    generateResolvConf = false
  1. I exited wsl and then issued a wsl --shutdown

  2. entered wsl force deleted the /etc/resov.conf to stop it being a symbolic link

sudo rm -fd /etc/resov.conf

  1. I exited wsl and then issued a wsl --shutdown

  2. entered wsl and recreated a resolv.conf

    sudo  touch /etc/resov.conf
    sudo  nano /etc/resov.conf
  1. Added the following line to the /etc/resolv.conf

nameserver 8.8.8.8

  1. I exited wsl and then issued a wsl --shutdown

  2. Entered wsl and everything was now working

Starting the docker daemon (inside of WSL2) seems to trigger this for me, very reliably.

C:\Users\radix> wsl --shutdown
C:\Users\radix> wsl

radix@DESKTOP-HOBTFB6:/mnt/c/Users/radix$ cd

radix@DESKTOP-HOBTFB6:~$ host google.com
google.com has address 172.217.14.174
google.com has IPv6 address 2607:f8b0:4000:813::200e
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.

radix@DESKTOP-HOBTFB6:~$ sudo service docker start
[sudo] password for radix:
 * Starting Docker: docker                                                                                       [ OK ] 

radix@DESKTOP-HOBTFB6:~$ host google.com
;; connection timed out; no servers could be reached

@jordansissel This started happening to me yesterday, but it seems my whole network is busted:

$ host -t A google.com 1.1.1.1
;; connection timed out; no servers could be reached
$ ping 8.8.8.8
connect: Network is unreachable

Running with AV and Firewall disabled.

EDIT: I disabled, restarted, and re-enabled the WSL and Virtual Machine Windows Features and it looks to work now.

Also, this doesn’t seem to be resolved for me by switching to a different nameserver. It seems that after starting docker, eventually all network I/O completely stops working in my WSL2 environment.

For newcomers to this thread, try pinging a public IP address first to make sure that DNS is actually the culprit here (ping 8.8.8.8). I found myself at this thread because I was receiving error messages about DNS failing to resolve, but it turns out I had actually lost complete external internet connectivity (yet another issue with WSL…). If you’re doing local development, this may not be apparent at first because networking between the Windows host & WSL still works great (VS Code, Docker Desktop, https://localhost/my-app/, etc). In my case, it turns out that WSL loses internet connectivity if Windows enters sleep mode (https://github.com/microsoft/WSL/issues/4992). Until that issue is resolved, the only solution that seems to work for me is rebooting Windows. As a result, I’d also recommend turning off sleep mode when the laptop is plugged in via the power settings menu. If the problem is actually DNS, then follow these steps instead: https://github.com/microsoft/WSL/issues/4285#issuecomment-522201021

@nonbeing make sure resolv.conf is a file and not a link

ls -la /etc/resolv.conf
-rw-r--r-- 1 root root 185 Sep 11 16:32 /etc/resolv.conf

@BtbN thanks boomer.

So what is the underlying problem with this, the 172… is the host IP, right? The resolv.conf is trying to use the host for the DNS lookup? That should in theory be correct especially if you’re on a VPN and this needs to make a couple of hops. Somebody at the WSL dev team should make this a priority as it’s literally making the whole WSL2 tool unusable so it’s literally a blocking issue!

The fix to disable WSL/restart/enable WSL/restart in the “Windows Features” settings fixed it for me. The problem does seem related to the docker daemon.

/dupe #8365

What I experienced is a little different, on wsl2 ubuntu 20.04. DNS works fine with the default, generated /etc/resolv.conf, nameserver 172.17.0.1. But DNS stopped working once dockerd starts. I tried to disable the auto-generation using the method described earlier, and explicitly set nameserver to a DNS server, e.g. 8.8.8.8. But it did not work for me. DNS stopped working once dockerd starts, and even if I subsequently stopped dockerd. Noticing that dockerd creates an interface on 172.17.0.1, which may interfere with wsl2 DNS forwarding, I changed the docker config to make dockerd create intf in a different subnet. After that change DNS works when dockerd is running. There is no need to disable the default auto-generation of /etc/resolv.conf. DNS inside a docker container, e.g. minikube pod, needs more configuration. But that seems to be a separate issue.

The docker config change is simple. Just the following in /etc/docker/daemon.json:

{
    "bip" : "10.10.0.1/16"
}

Hi! We’ve identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

That is, again, not a fix, but just the workaround of using Google DNS. For one, it leaks DNS queries to Google, and it’ll also make it impossible to resolve internal names. So please don’t call it a fix. It really isn’t. And a whole program just to write google DNS into resolv.conf seems a bit over the top.

How is it that this issue was opened years ago, the other issue was opened 21 days ago, and this is the one that is closed?

I made this simple program the configures WSL DNS:

https://github.com/epomatti/wsl2-dns-fix-config

Hope it helps someone.

3 years later and we’re still here

I have the same, the connection works on a fresh reboot then it fails after some time

Example for a apt-get update image

My resolv.conf file image

We are a lot facing the same issue, I can’t believe Microsoft is not giving an official solution, or at least more communication on the issue. I planned to switch on Visual Code using a WSL2 hosted sources, but my nuget packages can’t even been restored due to this problem, it’s a pain…

Why is this closed…

The resolv.conf workaround unfortunately prevents the typical method of finding the DISPLAY for X from working. However, I’ve found this can be placed in .bashrc/.zshrc instead:

export DISPLAY=`netsh.exe interface ip show ipaddresses "vEthernet (WSL)" | head -n 2 - | tail -n 1 | awk '{ print $2; }'`:0.0

This is almost certainly a bug. There’s some parity between WSL 1 and 2. I am on a fresh image of Windows v2004. My company rolls out a VPN to us and preconfigures firewalls, which I can’t change. This shouldn’t really be relevant as I think the real issue is WSL. I need to use our internal DNS servers to get to our internal servers etc etc. For those that don’t need this then you’d just use 9.9.9.9 or your preferred DNS provider. For me, I’d use 10.x.x.x.

If you look at a WSL1 box you see something like this in /etc/resolv.conf

# 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 10.7.xx.xx
nameserver 10.9.xx.xx
nameserver 192.168.1.1
search **lan**

WSL1 is working great because the resolv conf is getting provisioned perfectly.

If we look at WSL2 we see 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 172.17.128.1

The custom nameservers are completely missing. WSL1 is correct and WSL2 is broken. Seems that this behavior was somehow not ported over or simply broken?

The fix is to do what others said above, which I won’t repeat. For those who don’t need corporate DNS then you’d set to 9.9.9.9 and those who need corporate then make sure you set to your corporate DNS. Obviously, this sucks because 1. provisioning manually generally sucks and 2. if corporate DNS IP addresses update then your VM breaks.

This has nothing to do with virtual network adapters (at all).

I think it’s clear what WSL2 needs to fix though.

Here’s some more proof that if resolv.conf was correct then things would work: (WSL2 VM)

# working
$ host -t a google.com  10.7.xx.xx
Using domain server:
Name: 10.7.xx.xx
Address: 10.7.xx.xx#53
Aliases:

google.com has address 172.217.5.206

# broken (probably a firewall?)
host -t a google.com 9.9.9.9
Using domain server:
Name: 9.9.9.9
Address: 9.9.9.9#53
Aliases:

Host google.com not found: 3(NXDOMAIN)

I have reason to believe that this behavior STARTED happening with the latest update of Windows Insider. I’m on build 19013.1.

I’m not sure where the issue lies here - if it is an issue with Canonical and their Ubuntu deployment on WSL or if it is a Microsoft issue. Maybe another distro works - I’ll give that a go this weekend, hopefully. If I have time.

That said: I dare any of the folks in the WSL partnership to do the following:

  1. Install a stock Windows 11 build onto a bare metal system (NO VMs or containers - pretend you just picked this thing up from Best Buy)
  2. Install WSL - Ubuntu, latest release as of April 9, 2022
  3. Test DNS - works, right? Great! Did for me too.
  4. Edit your wsl.conf and allow edits to /etc/resolv.conf (hang with me here)
  5. Add a nameserver and IP, save, shutdown
  6. Since I know most of the devs are in the USA NW (not a knock, I also love coffee), drive to a coffee shop at least .5 miles from one you’ve never been to and join their WiFi
  7. Launch WSL and test DNS - works, right? Of course not, you edited resolv.conf and wsl.conf and those values don’t work on the new network.
  8. Remove the changes you made to resolv.conf and wsl.conf, ensure wsl.conf is back to default values, restart WSL via wsl --shutdown in a separate CMD window
  9. Forget the wifi network and re-join it
  10. Try WSL again - DNS works, right? … or does it?
  11. One last time, visit a 3rd coffee shop - one you haven’t ever been to
  12. Join the WiFi. test DNS.
  13. Stop the wsl service and try DNS again
  14. Shut down the laptop, boot and try again - Does DNS work via WSL?

If this works for you with a stock, bare-metal Windows 10/11 installation with absolutely zero modifications done by you, then I’ll admit defeat.

And if someone at Microsoft actually does this, and shows that it works (via Twitter, whatever) I’ll send you a Texas Brisket (Prime, not Choice) smoked on Oak and Hickory from my own backyard offset wood smoker. I don’t do pellets. I’ll send in a cooler, wrapped in heat-retaining packaging straight off of the pit, priority overnight with an 8AM guaranteed arrival time and instructions on how to keep it warm from the cooler to your countertop that afternoon.

Once you edit resolv.conf, you should do: sudo chattr +i /etc/resolv.conf - which makes the file immutable so it won’t be overwritten next time you start WSL. Maybe useful: https://command-not-found.com/chattr

Editing /etc/resolv.conf makes DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0" not working… Hoping for a better solution to make them both works…

This is what you’re looking for: export DISPLAY=$(ip route | awk '/default via / {print $3; exit}' 2>/dev/null):0

With how a lot of people behave here, that seems not that unreasonable really. Any productivity on trying to solve the actual issue is long over, and just bickering is left.

After 3 years of radio silence we finally have Microsoft hard at work trying to solve this:

“/dupe https://github.com/microsoft/WSL/issues/8365”

Issue closed, problem solved! Now, all that needs to be done is to lock this thread so nobody can reply anymore.

It doesn’t work for a few thousands people in MS. I’m not saying it’s necessarily WSL2 issue. I’m saying it’s a big enough issue to at least investigate it.

I made a workaround for this on wsl2 by:

  1. Creating a resolve.conf file somewhere where it wont get deleted like /home/ubuntu/resolv.conf with content: nameserver 8.8.8.8
  2. On /etc/wsl.conf adding the following: [network] generateResolvConf = false [boot] command = “cp /home/ubuntu/resolv.conf /etc/resolv.conf”
  3. wsl --shutdown
  4. Start wsl. This way the correct resolv.conf is copied to /etc everytime on boot. Hope this helps.

Ahh, sorry for the hassle. Glad you figured It out though. But don’t use an ad firm as your DNS provider, use encrypted DNS:

1.1.1.1
1.0.0.1
2606:4700:4700::1001 
2606:4700:4700::1111 

@qhaas To avoid changes reverting back, you need to remove the file and recreate it. Because in the default state, it’s a symbolic link to a (in reality) read-only or protected file.

I made a gist with @Klein-Hu 's instructions. They worked like a charm for me.

Fix DNS resolution in WSL2

Whatever provides the internal WSL2 dns seems busted, but other dns servers are successful:

% cat /etc/resolv.conf
# 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 172.19.224.1

% host google.com 172.19.224.1
;; connection timed out; no servers could be reached

% host -t A google.com 1.1.1.1
Using domain server:
Name: 1.1.1.1
Address: 1.1.1.1#53
Aliases:

google.com has address 216.58.194.174

@benhillis Why do you close an unresolved issue? This one (contrary to the duplicit #8365) somehow shows how long is the history, how many users were affected, what they have tried, how many voted to resolve this problem etc.

For me disabling Windows Defender Firewall for Public Network solved the the problem.

Before disabling it I got timeouts. Using the DNS of my router worked though.

$ cat /etc/resolv.conf
# 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 172.26.224.1
$ nslookup google.com
;; connection timed out; no servers could be reached

$ nslookup google.com 192.168.178.1
Server:         192.168.178.1
Address:        192.168.178.1#53

Non-authoritative answer:
Name:   google.com
Address: 142.251.36.206
Name:   google.com
Address: 2a00:1450:4016:809::200e

After disabling Windows Defender Firewall the name resolution worked fine.

$ nslookup google.com
Server:         172.26.224.1
Address:        172.26.224.1#53

Non-authoritative answer:
Name:   google.com
Address: 142.251.36.206
Name:   google.com
Address: 2a00:1450:4016:809::200e

On 23.10.2021 22:13, Xiaonuo Gantan wrote:

For me, I solved it by editing |…/run/resolvconf/resolv.conf| as the root user inside WSL2:

|nameserver 1.1.1.1 |

That’s not a solution, but merely the same hacked workaround mentioned here countless times.

Just a tip, if @tof1a and @gitolicious 's command fails for you, you can also do it manually.

i.e.: Open powershell, execute Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses | Get-Unique | Select -First 3 | ForEach-Object {echo "nameserver $_"}; Copy the output, open /etc/resolv.conf with vim/nano and then paste it on the file.

Got excited when I found my WSL adapter also had manual DNS with no addresses. Alas, adding 1.1.1.1 here hasn’t fixed the issue for me, even tried a reboot (noting that my setting had disappeared on the WSL adaptor and I had to set them again).

EDIT: it seems odd to me, that even if I explicitly tell nslookup the IP of a DNS server it still fails. Does this shed any light on the problem?

> nslookup google.com 8.8.8.8
;; connection timed out; no servers could be reached

> ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=8.56 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=8.97 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=116 time=8.72 ms

@gnomeria if you run ls on /etc/resolv.conf, you’ll see that its a symlink to /run/resolvconf/resolv.conf. I was able to get around this by deleting the symlink and then adding a new file at /etc/resolv.conf

It seems to me that we need to use the nameserver generated by wsl to use xserver as described in #4106. Any solution so that both dns and xserver works?

@peter-jerry-ye You can use my solution from above to set the display variable, even when resolv.conf is modified:

export DISPLAY=`netsh.exe interface ip show ipaddresses "vEthernet (WSL)" | head -n 2 - | tail -n 1 | awk '{ print $2; }'`:0.0

The workarounds here have never worked for me. This bug makes WSL2 completely unusable for development (or anything really). I’m on build 19041.

I believe this is Windows Firewall related (for me at least). Looking in the Windows Firewall Logs I found the following:

2020-06-02 18:36:22 DROP UDP 172.29.75.219 172.29.64.1 53860 53 79 - - - - - - - RECEIVE 2020-06-02 18:36:27 DROP UDP 172.29.75.219 172.29.64.1 53860 53 79 - - - - - - - RECEIVE 2020-06-02 18:36:32 DROP UDP 172.29.75.219 172.29.64.1 53860 53 79 - - - - - - - RECEIVE

.219 is WSL2 and .1 is the Windows Host.

If I do the following DNS to the host IP immediately starts working (Admin powershell prompt):

Set-NetFirewallProfile -DisabledInterfaceAliases “vEthernet (WSL)”

I have default Windows Firewall settings I believe. I can see two dynamic rules that get created - but they don’t appear to be working:

HNS Container Networking - DNS (UDP-In) - E8E88949-89CC-4317-B2A0-B47EDAA08189 - 0 HNS Container Networking - ICS DNS (TCP-In) - E8E88949-89CC-4317-B2A0-B47EDAA08189 - 0

Fresh install of Ubuntu 20.04 from windows store after upgrading to win10 2004 for wsl2 – cannot ping google.com, etc inside my new VM 😦 but by IP works fine ping 172.217.10.142 so DNS definitely busted at the start.

I followed the workaround from the very helpful and heavily emojied post above https://github.com/microsoft/WSL/issues/4285#issuecomment-522201021 and pinging external domains works now:

# in WSL
cat << EOF | sudo tee -a /etc/wsl.conf
[network]
generateResolvConf = false
EOF

# in cmd
wsl --shutdown

# in WSL
sudo rm /etc/resolv.conf && echo -e "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf

(btw --shutdown is correct, not --terminate – at least now, in the public release of win10 2004)

Using build: 18932.1000: I ran into this issue on Ubuntu also. Sometimes rebooting windows host and executing wsl --shutdown works. Will look into it further as it occurs and check back on solutions.

I ran into this same issue; resolved for now after removing etc/resolve.conf and resetting the entire dns config via the resolvconf package, pointing to cloudflare’s 1.1.1.1.

I wasn’t having this problem until the newest Windows 11 update that recently occurred as of this post. I’ve tried all of the fixes mention above.

For context, I’m on a VPN using Cisco AnyConnect. I’ve tried both the Windows 11 version and the Microsoft Store version. I need to access a server on the intranet. (Of which, I do not know the IP of the internal DNS server)

As a hotfix, I created a static host file of the ip of the server I needed to ssh into. Kind of a gross fix, but it works if you already know the ip address of the server you need.

vi /etc/hosts

and add

<ip address of server> <domain.of.the.server.com>

In case it helps anyone, I have a workaround that I use to “fix” DNS after I connect to my VPN, as that’s where I see the issue. In WSL I run

export IPADDR=$(powershell.exe -Command 'Get-DnsClientServerAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -eq "Local Area Connection"} |Select-Object -ExpandProperty ServerAddresses' | tr -d '\r') && sudo -E bash -c 'printf "nameserver $IPADDR\nnameserver 1.1.1.1\n" > /etc/resolv.conf' && cat -A /etc/resolv.conf

which updates my /etc/resolv.conf file with the correct nameserver from my VPN. After executing this I usually have to also run in Powershell Restart-NetAdapter -Name "vEthernet (WSL)" -Confirm:$false to force the adapter to reset, and then my WSL connections are all good.

Static /etc/resolv.conf does not fix it for me, the symptom persists. @benhillis how confident are you that (1) the dupe issue encompasses enough of the discourse here and the details presented? And (2) resolving the issue with DNS is going to resolve issues with networking routing?

WSL1 is not a VM, so there is no routing and DNS forwarding required.

I think nslookup mostly bypasses the normal Windows name resolution? iirc the default Win32 API resolver just sends a request to every single configured DNS server, and whoever replies first wins. No idea how up to date that knowledge is though.

If it affects all people in that network, but only a small handful of people outside of it, that VERY much hints at an issue with the network, not WSL or anything else.

Short answer is that there are a variety of work arounds that don’t work universally. Corp vpns can have over 40 virtual adapters setup and diagnosing is tough, especially where permissions / visibility are difficult. Wsl1 typically works A-OK where wsl2 fails. The fact that nobody from MS has commented in almost 3 years speaks volumes. As for me, I’ve switched to a Mac and the lack of official support on this issue was a big reason why

Not being too much of a network guru, but Mac would have the same issue, which I’m sure you know 😃 But I get your point. However, counterpoint: I’m sure Apple would have just told you to take this to the Genius Bar and pay $150 to be told that they won’t look into the issue.

The network packets just aren’t making it to the right place for X or Y reason, and in this case I don’t think they’re even making it off of the host. It works for some, but not all. VPN (as in others’ cases) or no VPN (as in my case), WSL just isn’t routing the packets where they need to go in a reliable manner.

I did set up a bash script to invoke a powershell prompt, list the NICs, grab the IP of the NIC with the lowest metric and add that to /etc/resolv.conf on login in ~.bashrc. It did fix my specific issue, but I shouldn’t have to do that, which is why I’m still bumping this thread. Bonus - it worked with VPNs too. It’s here, if anyone wanted to tinker with it. The problem I still have with it is it needs to run as root on login, and admittedly its been a few years since my last RHEL Engineering course for something as basic as this so I’m probably forgetting a trick or two…

It should also probably use powershell to grab the DNS suffix to append to the nameserver line in /etc/resolv.conf after the IP but again, it works for my specific use-case so I didn’t need to do that. But maybe another variable set to DNSSUFFIX=powershell.exe <some command>, if a search domain is needed.

Then: echo “nameserver $DNSRESOLVER” |sudo tee /etc/resolv.conf > /dev/null echo “search $DNSSUFFIX”|sudo tee /etc/resolv.conf > /dev/null

You’ll need to type in your password upon WSL’s launch for sudo as I didn’t quite figure out how to work around that, should anyone implement this (and I hope not… dear god, I am definitely not a programmer, nor do I really qualify as a competent script-kiddie). But maybe someone more proficient than I can see what I’m trying to do and can enhance this a bit.

#!/bin/bash
### This script assumes an Ubuntu WSL2 installation with a BASH shell, which is the default configuration
### Save this script in ~ and edit ~/.bashrc. At the end of the file, add a new line and just type in the path to this script.
# 
## Example: 
## Create a file called ~/dnsresolv.sh and paste these contents into the file. 
## Save and go back to the CLI
## Run this command to make the script read/write/executable (r/w/x) for you, r/x for group and r/x for everyone else: 
##        chmod 755 ~/dnsresolv.sh
## Edit ~/.bashrc (or whatever file is sourced by your shell of choice upon login), and on the last line, append and type:
##        ~/dnsresolv.sh
## Save the file
## Exit WSL and re-launch a new shell or type 'source ~/.bashrc' in current shell and input your password for sudo when prompted
# 
# 
# 
### Determine NIC with lowest metric (current Windows default NIC)
DEVICEALIAS=`powershell.exe 'Get-NetIPInterface -ConnectionState Connected|Sort-Object -Property InterfaceMetric|Select-Object -Unique InterfaceAlias,IPv4 -First 1'`
#
### Determine DNS server from host WiFi network
DNSRESOLVER=`powershell.exe 'Get-DnsClientServerAddress -InterfaceAlias $(DEVICEALIAS)'|grep IPv4|awk '{print $4}'|tr -d '{}'`
#
### Apply same nameserver to resolv.conf
echo "nameserver $DNSRESOLVER" |sudo tee /etc/resolv.conf > /dev/null
exit 0

It honors them just fine if everything is working as intended. WSL comes with a small DNS proxy on the Windows-Host, which obviously follows Windows DNS settings, and acts as DNS resolver for WSL. The only time it breaks is if you have VPNs or other software messing with Firewall rules regarding DNS, in order to “protect” against leaks.

What if I don’t want it pointing to DNS on the internet? What if I want it to point to the DNS server that Windows uses, such as a LAN DNS resolver, and it changes because I hop around to different company networks? Windows handles this already. All /etc/resolv.conf needs to do is use whatever Windows is set to use, probably on the lowest metric device in use.

Note that I mean “hop around to different company networks” as I physically go on-site and connect to various wifi networks. If I use a VPN, I am fine making this more of “my” problem.

I’m not editing this file over and over.

Is there any other solution than doing this every half an hour? image

Following Process not working:

  1. sudo nano /etc/resolv.conf
  2. Put the following lines in the file nameserver 8.8.8.8

ERROR: [ Error writing /etc/resolv.conf: No such file or directory ]

For me the problem was that I had the public profile of Windows Defender Firewall set to block all connections. Setting it back to “Block (Default)” fixed things for me.

I think the bug there is that the public firewall rules are applying to the WSL subnet or adapter. I couldn’t find a way to explicitly declare the WSL adapter as a private network, however.

Here an other approach to do the same from WSL: powershell.exe 'Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses | Select -First 3 | ForEach-Object {echo "nameserver $_"}' | sudo tee /etc/resolv.conf > /dev/null You can run this command in wsl each time you have your DNS configuration which have changed. It will configure your /etc/resolv.conf with the top 3 DNS servers (Linux do not support more than 3)

This needs to be fixed ASAP

I’m running Build 20201.rs_prerelease.200822-1922 and this happened to me a couple of times. I tried the workarounds but it didn’t work even after I restarted my host machine. Eventually I found that if I don’t mess with resolve.conf, a reboot would fix things until it happens again. I don’t use any other firewall other than the default windows defender.

I am also on the same windows build and a reboot doesn’t work for me. I have tried all the workarounds here and nothing is working for me. Please help. I believe it has something to do with the following, but have no idea how to fix it:

Ethernet adapter vEthernet (WSL):

Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . :

I got this by running ipconfig on CMD

I followed this https://github.com/microsoft/WSL/issues/5821#issuecomment-684092757 and it works now!! Hope it helps

I’m running Build 20201.rs_prerelease.200822-1922 and this happened to me a couple of times. I tried the workarounds but it didn’t work even after I restarted my host machine. Eventually I found that if I don’t mess with resolve.conf, a reboot would fix things until it happens again. I don’t use any other firewall other than the default windows defender.

So to sum up, for anyone tumbling here by google search : if inside a WSL2 with a default configuration, the DNS does not work, one of the possible explanation is that some firewall is blocking WSL2 from reaching the windows local dns resolver. Please check :

  • do you have an external firewall (McAfee, Avast, etc…) ? Do it work if you disable your external firewall ?
  • if you do not have an external firewall, is your PC managed by IT Admins in your company ? Some GPO/CSP might prevent the firewall rules created by WSL2 to work
  • if you completely disable the windows firewall, does it work ?

If none of the above works, your problem is probably somewhere else. Otherwise, it’s very likely a firewall issue, keep looking.

I’m really hoping a solution is found. I’m unfortunately having mixed results with the workarounds myself. On one machine the workaround does help, on another not at all. This is really frustrating and blocking me from adopting WSL 2 in my current workflow.

Just updated to the production version of windows 10 v2004, installed WSL2 and Ubuntu 20.04 from the Windows Store and verified via powershell it was using WSL2. I am not on a VPN, nor am I using a proxy. My firewall/antivirus are but those of Microsoft’s that ship with Windows 10 Pro for Workstations.

I too noticed DNS wasn’t working inside the WSL2 Ubuntu 20.04 environment. Adding the Google DNS servers to ‘/etc/resolv.conf’ resolves the issue, but my changes to ‘/etc/resolv.conf’ keep getting reverted every time I restart despite adding the blurb to ‘/etc/wsl.conf’ mentioned above by @non-static

Installed WSL 2 today on 19041.264

Network is unreachable from Ubuntu 20.04 vEthernet (WSL) adapter is correctly created and its IP is 172.23.64.1 However, even that IP is unreachable from inside WSL 2.

Changing the content of /etc/resolv.conf (and of /etc/wsl.conf doesn’t help).

ifconfig doesn’t return anything at all.

Going back to WSL 1 for stability for now. I hope this gets fixed fast as it’s a breaking issue.

Using nameserver 1.1.1.1 in /etc/resolv.conf allows me to reach the internet - but doesn’t allow me to reach the NAT-network behind my router. In my case, this is a deal breaker. Seems I’ll be forced back to using linux as my base OS instead of Windows.

Did you enter ‘wsl --shutdown’ into the cmd?


From: ambar notifications@github.com Sent: Wednesday, September 11, 2019 2:36 PM To: microsoft/WSL WSL@noreply.github.com Cc: mahsoommoosa42 mahsoom_m@outlook.com; Comment comment@noreply.github.com Subject: Re: [microsoft/WSL] WSL2 DNS stops working (#4285)

@Klein-Huhttps://github.com/Klein-Hu : tried your workaround, followed your steps, but it doesn’t seem to be working for me.

My /etc/resolv.conf file is getting wiped out every time I relaunch wsl2 😕

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/microsoft/WSL/issues/4285?email_source=notifications&email_token=AFA4ITKHNAZWNB7F7W6376LQJCYK7A5CNFSM4H65IQMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6NZ27Y#issuecomment-530292095, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFA4ITLPNO6V63C5UXARNC3QJCYK7ANCNFSM4H65IQMA.

Yeah. I did the same. I suppose it’s occuring due to the modifications to network settings with the last fast ring update.

Get Outlook for Androidhttps://aka.ms/ghei36


From: NonStatic notifications@github.com Sent: Saturday, August 17, 2019 9:09:55 AM To: microsoft/WSL WSL@noreply.github.com Cc: mahsoommoosa42 mahsoom_m@outlook.com; Comment comment@noreply.github.com Subject: Re: [microsoft/WSL] WSL2 DNS stops working (#4285)

My workaround:

  1. Create a file: /etc/wsl.conf.
  2. Put the following lines in the file

[network] generateResolvConf = false

  1. In a cmd window, run wsl --shutdown
  2. Restart WSL2
  3. Create a file: /etc/resolv.conf. If it exists, replace existing one with this new file.
  4. Put the following lines in the file

nameserver 8.8.8.8

  1. Repeat step 3 and 4. You will see git working fine now.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWSL%2Fissues%2F4285%3Femail_source%3Dnotifications%26email_token%3DAFA4ITLUCJ7RBWMFDIP3MHLQE5XIXA5CNFSM4H65IQMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4QCPPI%23issuecomment-522201021&data=02|01||73660638a70d4dbc6c4f08d722c49219|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637016099969731395&sdata=6rg9%2FiwAZkJoOhwhu6sHElqoJptYoS19AbuYTY5flPw%3D&reserved=0, or mute the threadhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAFA4ITMQRWJZKXU26K6BC33QE5XIXANCNFSM4H65IQMA&data=02|01||73660638a70d4dbc6c4f08d722c49219|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637016099969741400&sdata=ufzaqjmQaVAOOmGeoirghbUOw9ZddYre3JAnJcprh5k%3D&reserved=0.

Maybe it is related to this: #4275

It’s been a while since I’ve had this problem, but it happened again today. Typical symptoms – dns timeouts. Targeting other DNS servers directly works fine (local router’s dns, google dns, etc). The default WSL2 dns server does not respond.

From further up this thread, lots of reports about firewall issues, so I can report that DNS(1) fails, but then if I disable the Windows Firewall, DNS(1) works again.

(1) “DNS” aka the default wsl2 dns server which on my system is some WSL-internal 172.20.128.1 address – the same address as the default route.

Using nslookup from the Windows side, I can use the WSL dns server (setting server 172.20.128.1). Inside WSL, however, it times out unless I disable the firewall.

Hope this helps one of us eventually solve this 🤷‍♂️

just bickering is left

You should self-reflect on why. Every second comment here is you saying “Works for me!”.

That sounds like a completely different issue than the one this issue is about. The primary issue with DNS is that a lot of VPN Software, or just sometimes Windows itself, somehow, ends up blocking access to the local DNS Forwarder used by WSL2. General internet connectivity is not typically affected by that, so that’s an entirely different issue.

And you are complaining about that on a public Github, that’s obviously not monitored by the responsible people? It’s very clearly something with your Network or Machine Config, given it works for other people. It’s not generally broken. Only your Admins can help you.

Yes, which is why I said you should investigate what’s special about your network and/or setup. Latest Docker on latest Windows 11 with WSL2 generally works. Most likely cause of this issue is an overzealous Firewall.

I installed docker using apt-get on an WSL2 “Ubuntu 20.04.4 LTS”-instance and I start the docker daemon like this to set the DNS-servers:

#!/usr/bin/env bash
dnsServersForPhysicalNetAdapters=$(powershell.exe -Command "(Get-NetAdapter -Physical | Get-DnsClientServerAddress | Where-Object -FilterScript { \$_.AddressFamily -eq 2 }).ServerAddresses")
DOCKER_OPTS=$((sort | uniq | tr -d '\r' | sed 's:^:--dns :' | tr '\n' ' ') <<< "$dnsServersForPhysicalNetAdapters")
echo "$DOCKER_OPTS"
sudo dockerd $DOCKER_OPTS

The above command gets all the DNS servers for all physical IPv4 network interfaces and sets the DNS servers in an corresponding manner on the docker daemon. This way the DNS lookup works for me during building and running of containers.

Great for you. The issue is that this does not happen for everyone.

The only time it breaks is if you have VPNs or other software messing with Firewall rules regarding DNS, in order to “protect” against leaks.

It also seems to break, at least for me, when Windows Firewall is set to “block all incoming connections including those in the list of allowed apps”, this one:

image

(Screenshot from here)

Which sort of makes sense but it was a bit surprising because with WSL1 or VirtualBox DNS worked fine, probably because the implementation is different.

When the setting is enabled (all incoming connections blocked), then WSL can’t send DNS queries to 192.168.something.something (I don’t remember exactly but it’s a different IP range than the network range).

Adding new firewall rules for the WSL interface didn’t help. And I have no VPN running, no other firewall/AV software. All my network connections are set to “public”.

Ended up using DNSCrypt-Proxy (in my resolv.conf) so I can do DNS-over-HTTPS to DoH providers like 8.8.8.8 or 1.1.1.1 and others. I didn’t want to remove the “block all incoming connections” setting.

Short answer is that there are a variety of work arounds that don’t work universally. Corp vpns can have over 40 virtual adapters setup and diagnosing is tough, especially where permissions / visibility are difficult. Wsl1 typically works A-OK where wsl2 fails. The fact that nobody from MS has commented in almost 3 years speaks volumes. As for me, I’ve switched to a Mac and the lack of official support on this issue was a big reason why

If I’m missing something glaringly obvious, I’m happy to look into it.

The problem is that I do exactly the same and everything Just Works.

I understand that I’d need to open a new terminal window after the network change happens.

No, you don’t need to do that.

It honors them just fine if everything is working as intended. WSL comes with a small DNS proxy on the Windows-Host, which obviously follows Windows DNS settings, and acts as DNS resolver for WSL. The only time it breaks is if you have VPNs or other software messing with Firewall rules regarding DNS, in order to “protect” against leaks.

So - I shared my research above a few weeks ago. No VPN. It just does not work reliably if you hop between networks like, say, home network and then moving on to a coffee shop wifi. And I have just a stock install of WSL. If I’m missing something glaringly obvious, I’m happy to look into it.

And yes, I understand that I’d need to open a new terminal window after the network change happens.

My workaround:

1. Create a file: `/etc/wsl.conf`.

2. Put the following lines in the file
[network]
generateResolvConf = false
3. In a `cmd` window, run `wsl --shutdown`

4. Restart WSL2

5. Create a file: `/etc/resolv.conf`. If it exists, replace existing one with this new file.

6. Put the following lines in the file
nameserver 8.8.8.8
7. Repeat step 3 and 4. You will see `git` working fine now.

delete the existing file with the command rm /etc/resolv.conf if you see any issues while creating the file.

image

I found this and it worked for me on Global Protects Prisma VPN check the names referenced here for your computer by doing an ipconfig /all

then from an Admin Powershell, do the following:

Get-NetIPInterface -InterfaceAlias “vEthernet (WSL)” | Set-NetIPInterface -InterfaceMetric 1 Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match “PANGP Virtual Ethernet Adapter”} | Set-NetIPInterface -InterfaceMetric 6000

It’s only in WSL where DNS is a problem unless I hack resolv.conf.

This statement needs some proof. Does DNS properly work inside Hyper-V virtual machines under the same conditions when it doesn’t for WSL?

It does. DNS is fine in a Hyper-V VM: image

This is a stock install of Hyper-V. Steps I followed:

  1. Enable Hyper-V under Additional Features for Windows
  2. Rebooted
  3. Create a VM template in Hyper-V for Ubuntu
  4. Boot to Ubuntu ISO and “Try Ubuntu” (so no install to virtual disk)
  5. Issued commands in the image, all worked fine

So once again, only WSLv2 has this issue.

This is a WSL2 problem. WSL1 worked - WSL2 is a write-off with this issue. Hopefully WSL3 will work (one-day). (classic alternating Microsoft versioning afterall)

You did something wrong with your computer if you experience this issue. Out of the box, on a clean Windows, DNS simply works in WSL2. And you are the person to investigate what particular actions that you’ve done cause this effect. After you do that, you either undo problematic change, or fix software that causes the effect, or complain to MS (or that software vendor): hey, guys, your stuff doesn’t work together, you can do X+Y+Z to reproduce it. Nobody here is going to analyze your setup for you.

PS. I had DNS not working on WSL2. And I figured out that it was caused by firewall settings set by sysadmins. And I demanded them to fix buggy settings, and now I have fully functional DNS, either with or without VPN.

So, you say that something breaks depending on Docker Desktop version. How this is related to WSL? WSL works without any Docker Desktop.

But some buggy VPN software installs such routes/fw rules that break WSL2 networking. It’s not WSL2 fault.

I experience this problem without a vpn (as originally reported). There is some correlation with folks reporting the problem while using a vpn, but that isn’t the only group of folks reporting this problem.

This is a three years old issue that doesn’t have a good solution from vendor? Is the only solution to really get rid of Windows all together ?

I think I tried everything (edited etc/wsl.conf and /etc/resolv.conf), but there was one last step when using VPN + WSL2:

In Windows, Powershell with Administrator rights, run:

Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "<VPN_InterfaceDescription>"} | Set-NetIPInterface -InterfaceMetric 6000

where <VPN_InterfaceDescription> should be replaced with the starting characters of the InterfaceDescription of your VPN network adapter. You can check the correct name using Get-NetAdapter (with and without VPN on, and you’ll see the Status change)

For example, if using Cisco AnyConnect VPN:

Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000

Thanks to this old comment of @coltenkrauter pointing to here. There is also some critique against this method, and an alternative represented in this blog post, but the method was not “just copy paste a script” (at least yet).

You’ll need to run this every time after connected to the VPN. It might be handy to save the script as .ps1 file and create a shortcut to desktop with “Location of Item” defined as

"C:\Program Files\PowerShell\7\pwsh.exe" -ExecutionPolicy Bypass -File "C:\path_to_the\VPN for WSL.ps1" -WindowsStyle Hidden

The reasoning for all this is explained in the linked blog post.

Restarting the Windows vNIC solved this problem for me. Just run a privileged powershell with Restart-NetAdapter -Name "vEthernet (WSL)"

PS C:\WINDOWS\system32> Restart-NetAdapter -Name  "vEthernet (WSL)"
PS C:\WINDOWS\system32> wsl --status
Default Distribution: Ubuntu
Default Version: 2

Windows Subsystem for Linux was last updated on 08.11.2021
WSL automatic updates are on.

Kernel version: 5.10.60.1

This started happening for me too and is making WSL2 completely unusable for me at the moment. I need to use both Docker and our company VPN, and both of those seem to trigger weird interactions with name resolution in WSL2.

Weirdly enough, $ ping google.com works fine, but other sites like $ ping github.com don’t. On my Windows host, all of these work perfectly.

I’ve tried every workaround listed in this thread, reinstalled WSL2 and Ubuntu, reinstalled Docker, and none of them work.

Turn off your VPN (just a comment, not a solution to the problem). I followed the instructions by @non-static and was not able to ping google.com until AFTER I turned off my VPN connection. When I turned on my VPN again, ping: google.com: Temporary failure in name resolution. So in my case, running VPN seems to be related to the problem.

Hello,

Same issue on Windows 11 and WSL 2 with a Debian distribution. When putting generateResolvConf to false, each time I restart the WSL, the /etc/resolv.confdoes not exist.

wsl --status
Default Distribution: Debian
Default Version: 2

Windows Subsystem for Linux was last updated on 07/10/2021
WSL automatic updates are on.

Kernel version: 5.10.60.1

Addition to @SteveBurkettNZ, might be debian-based problem, i had this problem on Debian’s version

3 Years and 0 replies from Microsoft, awesome! 🎉🎉🎉

Did recreating the Virtual Adapters not help?

I found that it did have to to with the Virtual Network adapters. In simple cases it was easiest just to recreate them, in others I noticed VMs had been set to local only.

@dev-SR You probably still have the symbolic link there, delete it first and try again.

An even nicer solution to an ugly problem, thx. I think we should add Get-Unique (or uniq in the WSL world) to avoid duplicates. As previously we appended to the existing reoslv.conf I modified the tee command as well.

❯ powershell.exe 'Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses | Get-Unique | Select -First 3 | ForEach-Object {echo "nameserver $_"}' | sudo tee -a /etc/resolv.conf > /dev/null

Nice idea. Be aware this command is dependent on your OS language. E.g. in German you need to grep for "DNS-Server.*: [\.0-9]+\s*$" I think we would be better off using pure PowerShell commands to extract the value

Get-DnsClientServerAddress |
  Select-Object -ExpandProperty ServerAddresses |
  Select-String -Pattern '(\d+\.\d\.\d+\.\d+)' |
  ForEach-Object {$_.Matches[0].Groups[1].Value} |
  Select -First 1

Full command would be: PowerShell on Windows:

> $DnsIP = (Get-DnsClientServerAddress | Select-Object -ExpandProperty ServerAddresses | Select-String -Pattern '(\d+\.\d\.\d+\.\d+)' | ForEach-Object {$_.Matches[0].Groups[1].Value} | Select -First 1)
> wsl -d Ubuntu-20.04 -e sudo sh -c "echo nameserver $DnsIP >> /etc/resolv.conf"

WSL:

> DnsIP=$(powershell.exe "Get-DnsClientServerAddress | Select-Object -ExpandProperty ServerAddresses | Select-String -Pattern '(\d+\.\d\.\d+\.\d+)' | ForEach-Object {\$_.Matches[0].Groups[1].Value} | Select -First 1")
> sudo sh -c "echo nameserver $DnsIP >> /etc/resolv.conf"

In my case, the DNS was resolving names just fine on Windows, but not in one of the subsystem distros after I deleted and recreated a WiFi connection in Windows (to fix a different, auto-connect-after-pc-restart, issue).

To fix that I ended up executing the following commands from PowerShell on Windows:

# get the first DNS IPv4 address on Windows
> $DnsIP = (ipconfig /all | Select-String -Pattern 'DNS Server.*: ([\.0-9]+)\s*$' |
                 ForEach-Object {$_.Matches[0].Groups[1].Value} | Select -First 1)
# append distro's resolv.conf with the one from Windows
> wsl -d Ubuntu-20.04 -e sudo sh -c "echo nameserver $DnsIP >> /etc/resolv.conf"
# it prompted for distro password

which updated the subsystem distro (which was misbehaving) with same DNS IPv4 address as Windows 10.

If the distro has only the root user and sudo command is not installed (typically the case with default Alpine install), drop sudo from the command above to skip the password prompt.

We can also do it from Unix shell:

# compatible with distros without `grep -P`
> DnsIP="$(ipconfig.exe /all | grep -E "DNS Server.*: [\.0-9]+\s*$" | grep -Eo "([0-9]+[.0-9]+)")"
> sudo sh -c "echo nameserver $DnsIP >> /etc/resolv.conf"

The fix to disable WSL/restart/enable WSL/restart in the “Windows Features” settings fixed it for me. The problem does seem related to the docker daemon.

this solved for me

Rebooting caused those etc files to be regenerated, for me. It has to do with a virtual network adapter from what I’ve read, and those get recreated every reboot. (Not a definitive answer!)

Editing /etc/resolv.conf makes DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0" not working… Hoping for a better solution to make them both works…

I’m on build 18632, upgraded an existing WSL v1 Ubuntu distribution to v2 and DNS stopped working. Applied the wsl.conf / resolv.conf fixes but to no avail, DNS just won’t work at all. I also tried disabling WSL feature, reboot, enable WSL again, reboot, same thing still.

Just downgraded Ubuntu back to v1, DNS all working fine again. I may try a fresh Ubuntu v2 distribution (can I run this alongside v1 BTW?).

This is apparently how several default configuration errors are manifesting. For me, no editing of resolv.conf or disabling firewalls was working but disabling swap worked: https://github.com/microsoft/WSL/issues/5437#issuecomment-647161596

As @ScottyAU said :

I have default Windows Firewall settings I believe. I can see two dynamic rules that get created - but they don’t appear to be working:

HNS Container Networking - DNS (UDP-In) - E8E88949-89CC-4317-B2A0-B47EDAA08189 - 0 HNS Container Networking - ICS DNS (TCP-In) - E8E88949-89CC-4317-B2A0-B47EDAA08189 - 0

I had exactly the same thing : the same firewall rules, the same bug and all was working when I disabled the firewall on the vEthernet (WSL) interface as suggested by ScottyAU

But disabling the firewall was not an option for me. Turns out it was a GPO from my company which was responsible : ./Vendor/MSFT/Firewall/MdmStore/*/AllowLocalPolicyMerge

If this value is false, firewall rules from the local store are ignored and not enforced.

The firewall rules created automatically by WSL where simply ignored because of the GPO even though they where displayed in the firewall configuration and nothing was visually indicating that they where ignored.

As soon as the GPO was changed to allowlocalpolicymerge=true, all went back to normal without having to disable the firewall.

Hope it helps some of you.

Changing nameserver did not work for me.

$:/mnt/c/WINDOWS/system32$ cat /etc/resolv.conf nameserver 8.8.8.8 nameserver 8.8.4.4 $:/mnt/c/WINDOWS/system32$ ping google.com ping: google.com: Temporary failure in name resolution

I don’t have any VPN running now. But I have NordVPN installed. No third-party anti-virus or Firewall solutions installed.

[Edit]: I forgot I had Checkpoint VPN and uninstalling it worked. Related #4246

Also having regular problems with DNS and WSL2, 2004. Only wsl --shutdown helps…

Just for the info, if your DNS stops working only after connecting to Cisco AnyConnect VPN, check out https://github.com/microsoft/WSL/issues/4277#issuecomment-561649724

Perhaps related: I just noticed that something has being creating tons and tons of inbound rules at the Windows Firewall configuration relative to port 53 (DNS):

image

They are all of two types:

HNS Container Networking - ICS DNS (TCP-In), associated to svchost.exe. HNS Container Networking - DNS (UDP-In), for any program.

I’m at Windows 10 Pro build 19564 with WSL2, using regularly Ubuntu 18.04.4 LTS and Docker CE 19.03.6 (from the Ubuntu packages provided by Docker [1], not the new experimental Docker for Windows that uses WSL2).

[1] https://docs.docker.com/install/linux/docker-ce/ubuntu/

If they’re inbound rules, my first guess is that these are created by WSL2 for a local DNS server used on things like localhost resolution to the ip address of the WSL2 network interface.

It concerns me that so many rules have being created at the firewall, and I’m unsure about removing them, but could it be related that this registration process somehow fails, or it works but the addition of so many rules delays the actual DNS responses?

My workaround:

  1. Create a file: /etc/wsl.conf.
  2. Put the following lines in the file
[network]
generateResolvConf = false
  1. In a cmd window, run wsl --shutdown
  2. Restart WSL2
  3. Create a file: /etc/resolv.conf. If it exists, replace existing one with this new file.
  4. Put the following lines in the file
nameserver 8.8.8.8
  1. Repeat step 3 and 4. You will see git working fine now.

Ran into the same issue yesterday and couldn’t figure out why. That workaround actually solved the issue for me, thanks!

This happened suddenly, I just removed /etc/resolv.conf rebooted and let it regenerate the file, this makes sure you are not hardcoding your DNS server for easing further troubleshooting and keeping installation as close to defaults as possible. Most people want the DNS to follow in WSL if you decide to tether internet via phone, use VPN provider etc.

@hwasoocho no, sorry. After some time (and maybe some windows updates) it magically stopped being a problem.

Running insider 10.0.18980.1, kernel 4.19…67 Seems as if the dns resolver running on 172 is single threaded? Request that timeout seem to block.

I am seeing this same DNS behavior on Build 18941. The local DNS server is not responding but I can route out to the internet and everything works fine once I set a manual resolv.conf. Using both the official Kali and Ubuntu distros in the store, converted to WSL 2. I have no other Hyper-V VMs.

Ifconfig:

bond0: flags=5122<BROADCAST,MASTER,MULTICAST> mtu 1500 ether 0a:b1:11:d2:aa:66 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.201.80 netmask 255.255.0.0 broadcast 172.18.255.255 inet6 fe80::215:5dff:fe9a:1fe3 prefixlen 64 scopeid 0x20<link> ether 00:15:5d:9a:1f:e3 txqueuelen 1000 (Ethernet) RX packets 11 bytes 1507 (1.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 1232 (1.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 8 bytes 560 (560.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 560 (560.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

sit0: flags=128<NOARP> mtu 1480 sit txqueuelen 1000 (IPv6-in-IPv4) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0