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
15
Answers
The generated file /etc/resolv.conf is:
..had to change it to
which resolves the problem
Most probably, the Distribution gets its own virtual adapter, first there are some steps you might try:
Need to check if the packets really go through the Windows firewall
Then check
%systemroot%system32LogFilesFirewallpfirewall.log
If packets are not going through firewall most likely the distribution gets it’s own Virtual Adapter, check what IP gets distribution from inside Debian with:
ifconfig
or if you don’t have
ifconfig
:or
ipconfig
on the Windows WSL2 host machine and look what IP takes the machine unde WSL adapterThe work around is to use a script that does :
a. Get Ip Address of WSL 2 machine
b. Remove previous port forwarding rules
c. Add port Forwarding rules
d. Remove previously added firewall rules
e. Add new Firewall Rules
An alternative solution is to go to Hyper-V Manager and change the Virtual Switch that is bound to the physical NIC
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/resolv.conf to become "corrupted"
/etc/wsl.conf
.cmd
window, runwsl --shutdown
/etc/resolv.conf
. If it exists, replace existing one with this new file.git
working fine now.2 Remove corrupted Network Interface Drivers (could be permanent)
First go to device manager
Show hidden devices
Delete all Hyper-V Virtual Switch Extension Adapter
I was experiencing the same issue.
Do
cat /etc/resolv.conf
, and see if the output has something like this:You’ll need to change the nameserver to
8.8.8.8
, so runsudo 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.
For me, I had a fresh Ubuntu 20.04 WSL instance, after installing apache and allowing the apache profile using this command
Then,
I noticed that this issue has triggered and after disabling the firewall again using
everything worked just fine.
it worked for me, i’m using CiscoAnyConnect for VPN
Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1
Credits: Cisco AnyConnect
Check what antivirus you are using. I was having McAfee and endpoint security enabled. If disconnect End Point security firewall connectivity will work straightaway (no reboot required).
https://kc.mcafee.com/corporate/index?page=content&id=KB91411
Maybe it was a coincidence, but activating Hyper-V by running
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
in Powershell as administrator and restarting appeared to solve the issue for me when nothing else did. I had tried most solutions except the one involving Hyper-V Manager; I was activating Hyper-V to try that one but ultimately I didn’t have to do anything else.If it was a coincidence, it is possible the archive.ubuntu.com servers were temporarily unavailable. The fact that I never lost the ability to ping other addresses supports this. A comment on this AskUbuntu question states:
In other words, sometimes this issue is server-side. I don’t think anyone here has mentioned that possibility yet.
I had the same error when I applied Windows NTFS drive compression on disk
C:
. Further investigation shown, that compression of only two folders leads to that error:%LocalAppData%PackagesCanonicalGroupLimited*
)%TEMP%
(i.e.C:Users<Username>AppDataLocalTemp
)So you if you have
Temporary failure resolving...
error withsudo apt-get update
on WSL I recommend not to apply NTFS disk compression to system drive at all, or at least keep that two directories uncompressed.Also don’t forget to reboot your WSL in CMD or PowerShell terminal after uncompression with
wsl --shutdown
Run these commands on cmd:
I solved the issue changing
/etc/resolv.conf
to:and then
actually ‘locks’ the file with the
+i==immutable
attribute and hence cannot be regenerated by the OS.This way the user-modified
/etc/resolv.conf
will be persistent.I found creating the
/etc/wsl.conf
didn’t work, but left it anyway:after editing in /etc/resolv.conf . it resolved issue permanently
If it worked fine before and now it doesn’t.
Had the same error, now I can solve it with the following steps:
-Uninstall installed districts.
-Uninstall Docker (if you have it)
-Open your console in admin mode, and type:
to list the installed distros.
-Remove all additional distros from the console with the following command:
In NAME_DISTRO change with your distro. Delete each of the distros until you have none.
https://learn.microsoft.com/en-us/windows/wsl/install-manual
It will provide you with the following commands, execute them with the terminal in admin mode.
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
Install kernel if you have it already installed, you should not install it again.
Now if you can install the distro you want from the Microsoft Store.
I hope it works for you! 🔥
This is a known limitation of WSL 2 (WSL 1 vs WSL 2).
Ideal solution is to use WSL 1. Microsoft has recommended work arounds as well (doc), but those require admin privilege:
my solution in windows 10 wsl2 ubuntu 20.04 with a company is this one :
windows :
ipconfig /all
you take the information
and on ubuntu
change the nameserver X.X.X.X by the address serveurs DNS