Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows10 WSL2 Ubuntu / Debian # no network

After upgrading from WSL to WSL2

sudo apt-get update

not works any longer. After:

wsl --set-version Ubuntu-18.04 2

Output is:

> sudo apt-get update
Err:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu bionic InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

After going back to WSL1 the problem disappears again. Same on Debian and analogous in CentOS .. so WSL2 must have a bug.

The Windows10 build Version is 19041 and was installed today.

Any work around for WSL2? Regards

like image 781
Jundl Avatar asked Feb 17 '20 19:02

Jundl


People also ask

What version of Ubuntu does WSL2 use?

WSL supports a variety of Linux distributions, including the latest Ubuntu release, Ubuntu 20.04 LTS and Ubuntu 18.04 LTS.

Which Linux distro is best for WSL2?

WLinux is a custom Linux distro built from Debian specifically for use on the WSL. While other distros are available for WSL, WLinux is the first optimized for use by users of WSL for WSL. It helps developer run Linux tooling on Windows and integrates into perfectly into Windows.

Can you run Debian on Windows 10?

As of March 2018 Debian is available for Windows users through the Windows store as an app for the Windows Subsystem for Linux (WSL). The app gives you a Debian stable command line environment running on the Windows kernel (WSL1) or Hyper-V with the new WSL2 interface depending on your Windows 10 release version.


3 Answers

The generated file /etc/resolv.conf is:

nameserver 172.24.0.1

..had to change it to

nameserver 8.8.8.8

which resolves the problem

like image 109
Jundl Avatar answered Oct 18 '22 21:10

Jundl


Original Answer:

In my case I was using a VPN in Windows, when disconnecting from the VPN the problem was resolved.

Edit:

However, this is becoming a wider issue, it's happened again to me and I've solved it by removing Hyper-V Virtual Switch Extension Adapter.

The two solutions most widely used at the moment for this issue are:

1 Prevent /etc/resolfv.conf to become "corrupted"

  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.

Credits to NonStatic who shared it on github

2 Remove corrupted Network Interface Drivers (could be permanent)

  1. First go to device manager enter image description here

  2. Show hidden devices enter image description here

  3. Delete all Hyper-V Virtual Switch Extension Adapter enter image description here

Credits to Jaysonsantos who shared it on GitHub

like image 37
JesusIniesta Avatar answered Oct 18 '22 20:10

JesusIniesta


I was experiencing the same issue.

Do cat /etc/resolv.conf, and see if the output has something like this:

# 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.X.X.X

You'll need to change the nameserver to 8.8.8.8, so run sudo nano /etc/resolv.conf, edit and save the file.

However, this is more or less a temporary solution, as you'll need to do this every time WSL starts. You might wanna run a script that checks the nameserver and updates it to 8.8.8.8 every time you reboot wsl. This change does work for my WSL2-Debian. But I don't need to restart the WSL.

like image 12
kelvinelove Avatar answered Oct 18 '22 19:10

kelvinelove