Skip to content

WSL2 DNS stops working #4285

Closed
Closed

Description

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.

Activity

  1. jordansissel commented on Jul 8, 2019

    @jordansissel
    Author

    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
    
  2. lkuich commented on Jul 8, 2019

    @lkuich

    Jordan Sissel (@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.

  3. develleoper commented on Jul 9, 2019

    @develleoper

    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.

  4. heamaral commented on Jul 10, 2019

    @heamaral

    Maybe it is related to this: #4275

  5. bmpertierra commented on Jul 11, 2019

    @bmpertierra

    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.

  6. astamos commented on Jul 23, 2019

    @astamos

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

  7. mahsoommoosa42 commented on Aug 15, 2019

    @mahsoommoosa42

    Facing the same issue on 18956. manually setting resolv.conf is a temporary solution. adding generateResolvConf to false did not affect anything. What's with that ip address (one starting with 172) though? have never seen it before

  8. mahsoommoosa42 commented on Aug 15, 2019

    @mahsoommoosa42

    Facing the same issue on 18956. Git and Ping does not work.

  9. non-static commented on Aug 17, 2019

    @non-static

    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.
  10. mahsoommoosa42 commented on Aug 17, 2019

    @mahsoommoosa42
  11. nonbeing commented on Sep 11, 2019

    @nonbeing

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

  12. mahsoommoosa42 commented on Sep 11, 2019

    @mahsoommoosa42
  13. nonbeing commented on Sep 11, 2019

    @nonbeing

    Yes, I did.

  14. mahsoommoosa42 commented on Sep 11, 2019

    @mahsoommoosa42
  15. onomatopellan commented on Sep 11, 2019

    @onomatopellan

    Ambar (@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
    
  16. 271 remaining items

  17. Mithras commented on May 28, 2022

    @Mithras

    The higher level problem is that it is inconsistent to reproduce and difficult to diagnose.

    If you are in MS corpnet, you can repo it by installing any Docker after 3.5.2.

  18. LUC18fknU7P commented on May 29, 2022

    @LUC18fknU7P

    Yes, this also happened to me while using Docker. No VPNs or that kind of stuff.

  19. carlos-hdzm commented on Jun 7, 2022

    @carlos-hdzm

    Same thing happened to me. I was building a container and it worked fine, but then my computer ran out of space, so WSL2 crashed. I quit Docker, used wsl --shutdown and compacted the virtual disk. After starting Docker and WSL2 again, I used docker system prune. When I retried building the container, it started failing on build, unable to install Node packages because of the network connection. I tried wsl --shutdown again, and it didn't work. I can't modify resolv.conf.

    However, after a few tries, it works. I still don't know what the problem is.

  20. eg-fxia commented on Jul 11, 2022

    @eg-fxia

    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"
    }
    
  21. jikuja commented on Jul 13, 2022

    @jikuja

    The docker config change is simple.

    Did you report this on the docker repo(s)?

  22. ps2goat commented on Aug 11, 2022

    @ps2goat

    I had bridge IPs that I think are recreated by the WSL service. I deleted them with some PS commands after screwing them up, then new ones are created when I bring WSL back on line.

    This fix worked for me within WSL. I haven't used docker extensively on this new machine to verify the docker dns, but I have updated the docker dns on other machines and it worked inside docker containers.

    FYI, Windows 11 still has the extra adaptors, but you only see them in administrator tools from what I've read. I haven't had the need to dig in there, yet. Windows 10 had them in the standard "network adaptors" screen.

  23. petertirrell commented on Oct 31, 2022

    @petertirrell

    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.

  24. jordansissel commented on Oct 31, 2022

    @jordansissel
    Author

    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 🤷‍♂️

  25. jordansissel commented on Oct 31, 2022

    @jordansissel
    Author

    From a linked issue, possibly a solution for some of us will be released soon as noted in this comment: #8365 (comment)

  26. rcprior commented on Nov 1, 2022

    @rcprior

    The issue seems to be fixed: #8365 (comment)

  27. felipe-gustavo commented on Nov 8, 2022

    @felipe-gustavo

    I've tried to solve it for a whole week, thank you a lot Christopher Armstrong (@radix), I owe you my soul

  28. NanoWar commented on Jun 27, 2023

    @NanoWar

    Quick fix that worked for me:

    sudo ip addr add dev docker0 10.10.0.1/16
    sudo ip addr del dev docker0 172.17.0.1/16
    
  29. Mithras commented on Jun 30, 2023

    @Mithras

    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.

  30. SandysPappy commented on Sep 20, 2023

    @SandysPappy

    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>

  31. rwayan commented on Jul 30, 2024

    @rwayan

    Facing the same issue on 18956. manually setting resolv.conf is a temporary solution. adding generateResolvConf to false did not affect anything. What's with that ip address (one starting with 172) though? have never seen it before

    "After I removed the 172 address from the interface, DNS resolution returned to normal."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions