42

Running Ubuntu on WSL and trying to push to github and download new python modules using pip and I get this error.

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f9d654fe0b8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/tensorflow/

I had a look at the resolv.conf file and maybe its corrupted as it just gives a few lines of @@@. Anyone got any ideas how to fix this?

When I run l

ls -al /etc/resolv.conf
-rw-r--r-- 1 root root 261 Nov 28 12:54 /etc/resolv.conf

Update:

I managed to fix the problem. Needed to edit the file and add a line like this:

nameserver 8.8.8.8
8
  • It might be corrupted. When looking at what is contained in the /etc/resolv.conf it is actually a link to /run/resolvconf/resolv.conf The file is supposed to be automatically generated by WSL. Maybe you need to recreate the /run/resolvconf/resolv.conf file with just the line of # This file was automatically generated by WSL. To stop automatic generation of this file, remove this line.
    – Terrance
    Nov 28, 2019 at 18:40
  • Edit your question and show me ls -al /etc/resolv.conf.
    – heynnema
    Nov 28, 2019 at 19:29
  • I have edited the post
    – m_bash
    Nov 29, 2019 at 9:47
  • The symbolic link for /etc/resolv.conf is missing, and the static file contains garbage. So... temporarily edit /etc/resolv.conf (sudo -H gedit /etc/resolv.conf), remove everything there, and just enter 8.8.8.8 and save the file. Retest. Report back. Start comments to me with @heynnema or I may miss them.
    – heynnema
    Nov 30, 2019 at 1:38
  • @heynnema Tried that and still no change.
    – m_bash
    Dec 1, 2019 at 8:39

12 Answers 12

60
  1. Inside WSL2, create or append file: /etc/wsl.conf

  2. Put the following lines in the file in order to ensure the your DNS changes do not get blown away.(This will replace everything that might exist in wsl.conf. You can also use editor here.)

    sudo tee /etc/wsl.conf << EOF
    [network]
    generateResolvConf = false
    EOF
    
  3. In a cmd window (!!), run wsl --shutdown

  4. Start WSL2

  5. Run the following inside WSL2 (line with search is optional)

    sudo rm -rf /etc/resolv.conf
    sudo tee /etc/resolv.conf << EOF
    search yourbase.domain.local
    nameserver 8.8.8.8
    nameserver 1.1.1.1
    EOF
    
5
  • 4
    what is yourbase.domain.local? How to get those details? And, it's working for me after following only starting 3 steps!! What are we doing in step 2? Can you please add more detail? Jul 22, 2022 at 6:07
  • @shaikmoeed youcan find your base domain after running in powershell this ipconfig|findstr DNS-Suffix. The second step is overwriting the default system settings and redirecting all DNS queries via this resolv.conf file. If you have more questions please go to official docu here docs.microsoft.com/en-us/windows/wsl/wsl-config
    – mati kepa
    Jul 22, 2022 at 8:11
  • 1
    That would replace everything that might exist in wsl.conf so check the contents first or better use an editor
    – venimus
    Jan 2, 2023 at 15:55
  • @venimus good point, I will add additional warning to my solution
    – mati kepa
    Nov 29, 2023 at 9:09
  • why do I have to keep doing this on every restart of wsl? Dec 2, 2023 at 5:53
12

I have the same problem. It also seems to be realted to VPN. I found out, that it only fails the DNS lookup when I first connect the VPN before starting WSL-Ubuntu after System-Reboot. First starting WSL-Ubuntu and afterwards connecting the VPN seems to work.

3
  • That doesn't work for me
    – David
    Jun 18, 2021 at 15:39
  • 1
    Thanks for mentioning the VPN! When I disabled my VPN (under Windows), the apt update in WSL started working.
    – userfuser
    Nov 18, 2021 at 17:29
  • I can manage to ping my host windows machine when I turn off my VPN but I cannot get it to work with the VPN no matter when I start WSL. Feb 27, 2023 at 11:46
6

For me it was a simple fix. From powershell:

wsl --shutdown

And then restart wsl and it worked. Yes, I know this solution is too simple and might not be good to you if trying to avoid reset to WSL. But in case you look for something simple, maybe worth trying

1
4

I had the same error. Pinging IP addresses worked, but no DNS resolution. Outside of WSL everything was fine. The problem was caused by OpenVPN for me, when I disconnected from my workplace's VPN, the error was gone.

2
  • Thanks, that was it for me! Turns out it is triggered by the 'block-outside-dns' flag in my config. Used to work fine, but no longer after updating to 2004!.
    – Vaal
    Jul 20, 2020 at 18:14
  • It is happened to me even without connecting the VPN
    – Guilherme
    Jun 23, 2021 at 14:35
4

When I ran ls -lah /etc/resolv.conf, I saw that it was a symlink to ../run/resolvconf/resolv.conf.

But then I noticed that ../run/resolvconf/resolv.conf didn't exist, and in fact, although the /run/ directory existed, /run/resolvconf/ did not.

So I created that directory and also created an empty file sudo vim /run/resolvconf/resolv.conf.

Then I edited that file to contain:

nameserver 1.1.1.1

After saving that file, ping google.com worked!

(It seems like that file is required. I don't know how mine got removed.)

https://github.com/microsoft/WSL/issues/6601 was helpful for me.

3

I've had this issue random on multiple machines, old / new / W10 / W11. In my case if I turn off the Windows Defender Firewall -> DNS resolution works fine from WSL. Turning it back on and logging packet drops shows the issue at the public network profile:

#Version: 1.5
#Software: Microsoft Windows Firewall
#Time Format: Local
#Fields: date time action protocol src-ip dst-ip src-port dst-port size tcpflags tcpsyn tcpack tcpwin icmptype icmpcode info path
2022-02-01 20:30:34 DROP UDP 172.30.230.159 172.30.224.1 29101 53 45 - - - - - - - RECEIVE
2022-02-01 20:30:35 DROP UDP 172.30.230.159 172.30.224.1 18103 53 45 - - - - - - - RECEIVE

I fixed it by setting an inbound firewall rule for the WSL network adapter - run this in Powershell:
New-NetFirewallRule -DisplayName "WSL allow in" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

1
  • Similar solution for me. The culprit was employer's Trellix (McAfee) firewall. Temporary turning off the firewall (Quick Settings > Disable Endpoint Security Firewall) allowed WSL to resolve names successfully.
    – cfort
    Jan 17, 2023 at 14:46
3

The fix for resolv.conf by @matson kepson deals with DNS. If you can't ping IP addresses, the problem may be either in the firewall or in the VPN. You can fix it in Administrator's powershell.

Deal with the firewall, as @ElektronenVolt wrote:

New-NetFirewallRule -DisplayName "WSL allow in" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

Or with a sledgehammer:

Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"

Deal with the VPN:

Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000

The VPN in my case was a company VPN using Cisco AnyConnect. I needed the resolv.conf fix too.

Terminate the Linux VM before starting it again before you test the new settings:

wsl --shutdown
1
  • The sledgehammer worked for me, thanks @ferdinand-prantl. I have Sophos on top of windows firewall, so adding the rules for windows firewall did not seem to have any effects. With the sledgehammer, everything worked. Jun 29, 2022 at 14:56
2

I resolved issue in my Lab. You can use below steps for that.

    • Open Powershell as Administrator
    • Get-NetAdapter
    • New-NetFirewallRule -DisplayName "WSL allow in" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
    • Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)"
    • Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses | Foreach-Object { "nameserver $_" }
    • Copy all name server
    • open Distribution
    • sudo mv /etc/resolv.conf /etc/resolv.conf.old
    • modify the wsl.conf sudo nano /etc/wsl.conf
  • #[boot]
  • #systemd=true
  • [network]
  • generateResolvConf = false
    • sudo touch /etc/resolv.conf
    • sudo nano /etc/resolv.conf pest here nameserver in this file Ex: nameserver 8.8.8.8
    • save the resolv.conf
    • wsl --shutdwon and open it.
1
  • This is the only thing that worked. How grateful I am to you!
    – West Side
    Mar 5 at 14:19
1

In my case, none of above solutions working for me.

In the end, I've disabled Internet Protocol Version 6 (TCP/IPv6) in WLAN Properties of Network Connections Settings. The DNS working again somehow.

Configuration Screenshot:

Screenshot of Disabling Internet Protocol Version 6 (TCP/IPv6)

Ping GitHub.com Successfully Screenshot:

Screenshot of Ping GitHub.com Successfully

Source: https://unix.stackexchange.com/a/628767/338681

1

Try to ping any DNS:

ping 1.1.1.1

If you got timeout - it's not a DNS but an internet connectivity issue (your adapter has no internet access).

This may happen due to Cisco AnyConnect issue - not able to work with VirtualSubnets correctly.

Solution: execute following in the Windows Powershell

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

then

ping 1.1.1.1

More on that https://askubuntu.com/a/1404103/791374

And here https://gist.github.com/machuu/7663aa653828d81efbc2aaad6e3b1431

0

In my case, inside wsl, file: /etc/resolve.conf listed a non-working name server.

wsl --shutdown

did not resolve the issue.

However, restarting the entire Windows machine did solve the problem. After the restart, /etc/resolve.conf (inside wsl) got updated and now points to a working nameserver.

0

I just ran into this issue as well, which is documented on this thread [https://github.com/microsoft/WSL/issues/6404]. One of the comments had the answer for me, which was to put generateResolvConf = true. Not sure why doing the opposite of the original suggestion is the one solution that finally worked, but there you go.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .