8

I have a fresh installation of Windows 11 with ubuntu 20.04 installed inside wsl2.

When I try to perform an update sudo apt update or even ping google.com I get

Temporary failure resolving 'archive.ubuntu.com'

and

Temporary failure in name resolution

errors respectively.

I've tried:

  • Allowed wsl through the windows firefall using 'allow an app through the firewall' and selecting C:\Windows\System32\wsl.exe

  • Added inbound rule in firewall for port 3390

  • Set network profile to 'private' (although I would prefer to keep this public if there's a way to keep wsl working)

  • running New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow from a google search

EDIT: At this point I've tried every google result and still no solution. r/windows11 won't let me post unless it's a Monday (stupid). Also tried reinstalling ubuntu on wsl to no avail.

Kaigo
  • 215
  • 1
  • 2
  • 7
  • Does your Windows host ever connect to a VPN by any chance? – NotTheDr01ds Dec 03 '21 at 17:58
  • I have one installed but I turned it off. I would to be able to use with VPN though. Is that an issue? – Kaigo Dec 03 '21 at 18:45
  • Can you update your question with the current contents of /etc/resolv.conf? It should have an address in the private IP address space that corresponds to the default route shown by ip route. Can you ping this address? – NotTheDr01ds Dec 03 '21 at 21:01
  • 1
    And yes, VPN's can be problematic. At the least, there's usually additional work needed. At worst, they can completely break networking when active. Worry about that when you come to it, though. For now, let's focus on the general networking issues ;-) – NotTheDr01ds Dec 03 '21 at 21:03
  • Can you ping IP addresses (your PC, your router, Google DNS at 8.8.8.8, Cloudflare DNS at 1.1.1.1, …)? What’s in your WSL Linux’ /etc/resolv.conf? – Daniel B Dec 14 '21 at 16:44

2 Answers2

18

There is more than one cause for this problem.

The article WSL2 Network Issues and Win 10 Fast Start-Up advises to disable Fast Startup in Windows:

enter image description here


Another explanation is that switching networks (as between work and home) confuses WSL. The solution is to run a .bat file that contains the following:

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r

Still another explanation is that Windows automatically generates a resolv.conf file with a wrong nameserver.

To prevent this from happening, run the following commands:

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf
harrymc
  • 480,290
1

Just want to remind everybody that Win11 seems to be a stickler for admin access, like even to put a .bat file on C:

So that having been said, these rewriting of etc/resolv.conf to 8.8.8.8 worked as long as I did EVERYTHING as and from Administrator Access, including for me, starting my WSL2 Kali CLI as admin from Win11 task bar.