52

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
Tejes
  • 53
  • 1
  • 6
m_bash
  • 621
  • 1
  • 5
  • 4

14 Answers14

80
  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
    
mati kepa
  • 1,111
15

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.

9

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

justadev
  • 273
5

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.

Tejes
  • 53
  • 1
  • 6
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.

Ryan
  • 623
4

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

2

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

Jerry Chong
  • 211
  • 2
  • 5
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

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

Kirill
  • 111
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.

anneb
  • 111
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.

bischrob
  • 101
0

If you use VPN setup on windows, you may want to use dnsTunneling. For that you should use .wslconfig(according to [1]). The .wslconfig file can be edited from windows, open File explorer, enter in the search bar %USERPROFILE%. In the folder opened, create file .wslconfig .Open it with the editor of choice and add:

[wsl2]
dnsTunneling=true

Then from cmd:

wsl --shutdown

Reopen the wsl. To test it works:

ping google.com

[1]https://learn.microsoft.com/en-us/windows/wsl/networking

[2].wslconfig location

0

In my case, I was using Hyper-V Virtual Switch using ethernet adapter, and trying to access network using wifi, doesn't work and resulting in

ping askubuntu.com
ping: askubuntu.com: Temporary failure in name resolution

I changed the settings for WSL (Hyper-V firewall) in Virtual Switch Manager in Hyper-V from ethernet to wifi.

wsl --shutdown
wsl

then it works

ping askubuntu.com
PING askubuntu.com (172.64.150.156) 56(84) bytes of data.
64 bytes from 172.64.150.156: icmp_seq=1 ttl=56 time=37.6 ms
64 bytes from 172.64.150.156: icmp_seq=2 ttl=56 time=45.0 ms
64 bytes from 172.64.150.156: icmp_seq=3 ttl=56 time=122 ms
64 bytes from 172.64.150.156: icmp_seq=4 ttl=56 time=69.2 ms
^C
--- askubuntu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 37.586/68.462/122.069/33.079 ms
PHANTOM-X
  • 101