10

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.

5
  • Does your Windows host ever connect to a VPN by any chance? Commented Dec 3, 2021 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
    Commented Dec 3, 2021 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? Commented Dec 3, 2021 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 ;-) Commented Dec 3, 2021 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
    Commented Dec 14, 2021 at 16:44

3 Answers 3

19

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
5
  • 3
    thanks but didn't work.
    – Kaigo
    Commented Dec 14, 2021 at 15:50
  • Thank you, it did solve my problem, to anyone out there: Windows 11 Up to date > WSL 2> Debian could not install nvm or use nvm ls-remote - Disabling fast startup - Last script exeuction Solved the problem Commented Feb 7, 2022 at 21:31
  • I've lost count of the number of times I've had to recreate resolv.conf. Either Windows decides to delete it or update it with some nonsense. I just want it to work.
    – user24601
    Commented Mar 2, 2022 at 16:43
  • 1
    The resolv.conf did the trick for me, too Commented Nov 24, 2022 at 21:43
  • I had the problem on Windows 11, even though I have /etc/resolv.conf locked down already. Resetting the network as described above with WSL stopped did fix the problem for me though. Commented Oct 3, 2023 at 2:24
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.

1

Adding this setting to your .wslconfig file (in your Windows home directory) should enable networking support in the WSL virtual machines:

[wsl2]
networkingMode=mirrored

WSL should be stopped after changing .wslconfig for the changes to take effect: use wsl --shutdown from a Windows command shell. This is a relatively new feature (Sept 2023 update), requires build 22H2 (I have tested it only on Windows 11, but may work on up-to-date Windows 10). Details and other related configuration settings here: https://learn.microsoft.com/en-us/windows/wsl/networking.

To use the latest WSL2 subsystem, running wsl --update may be required.

On older versions of Windows, the only solution that I was able to use reliably and that also works while Windows has VPN running is to use 'wsl-vpnkit' (https://github.com/sakai135/wsl-vpnkit).

0

You must log in to answer this question.

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