Windows10 WSL2 Ubuntu / Debian # no network

Solution 1:

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

Solution 2:

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