Closed Fubuchi closed 4 years ago
The following fixed my problem: Upon examining the contents of /etc/resolv.conf, I discovered the file seemed to have been overwritten or corrupted. It contained nothing but a single line of
#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#...
Using sudo, I overwrote the contents of the file with the following:# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line.
nameserver 169.237.250.250
nameserver 169.237.1.250
Saved, restarted WSL, and it worked like a charm.My file was corrupted but fixing it, didnt get my internet connectivity back. Before WSL crashed a few times when deleting huge folders (node_modules). Maybe thats what corrupted that file.
What helped was the following: On cmd execute:
netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns
in WSL:
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'
found in #3438
using
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'
after connecting my VPN worked perfectly!
@df3l0p I've experienced exactly the same behaviour. Networking didn't work only in WSL 2, after downgrading Ubuntu to WSL 1 the connectivity issue didn't persist. As @michidk suggested above - I have overwritten the DNS settings with a public DNS server by running
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'
which fixed the issue.
I've just upgraded Windows to version 2004 (OS Build 19041.264) today to test out the new WSL 2.
EDIT: the issue comes back after restart. To fix it permanently: https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6
Note: originally
/etc/resolv.conf
was a symbolic link to/run/resolv/resolv.conf
. Creating aresolv.conf
file in/run/resolv
didn't fix this issue as it got deleted after invokingwsl --shutdown
and restarting Ubuntu. I had tosudo rm /etc/resolv.conf
and recreate the file as the gist says.
Thank you, it works for me.
I created this because of the need to rerun it now for every new distro created ... https://github.com/aaronlks/wsl2-19041-fixDNS/blob/master/fixdns.sh
sudo chmod 666 /etc/resolv.conf
echo "nameserver 208.67.222.222" >> /etc/resolv.conf
echo "nameserver 208.67.220.220" >> /etc/resolv.conf
sudo chmod 755 /etc/resolv.conf
sudo touch /etc/wsl.conf
sudo chmod 666 /etc/wsl.conf
echo "[network]" >> /etc/wsl.conf
echo "generateResolvConf = false" >> /etc/wsl.conf
sudo chmod 755 /etc/wsl.conf
hope this gets fixed eventually =)
I have been facing the same problem for the last day or so. In my case it turns out to be the firewall. At the working laptop, we use Avast, for me to make it work again I had to enable Internet Connection Sharing mode on the Avast firewall settings.
I am reporting here because it may be of some help to someone else out there.
I have the same problem when I'm connected via the Citrix VPN client when my distro is in WSL 2 mode. None of the workarounds appear to work for me.
I'm running Windows build 19041.329.
i've got no internet access in a newly installed ubuntu subsystem.
also running 19041.329.
Should the IPs of the subsystem and the virtual adaptor on the host be on the same subnet? they're not in my case.
I met same issue on 19041.329 with ubuntu 20.04.
got workaround from #5437 :
edit %userprofile%\.wslconfig
(create if not already exist) and add below option:
[wsl2]
swap=0
Seems like there are mutiple issues out there in regards to this "same issue". I read through much of them and with the help of my IT department we came up with a solution I've stated at #4246 here.
So I just worked with my IT Department on coming up with a fix. Here's what we found out and how we corrected it.
When you connect to Cisco Anyconnect WSL2 will NAT to the highest priority Ethernet Adapter. A newer version of Cisco Anyconnect from the Windows Store seems to correct this; however, it doesn't support Dual Factor Authentication. So to correct this we used a script that I saw mentioned elsewhere.
Steps:
Restart Computer (or begin from fresh start) Login to Computer, Connect via Cisco AnyConnect Run a script from Powershell that includes the follow (Note: your adapter name may need to be changed on Line 2 in quotes) Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1 $VPNInterfaceName = "Ethernet 3" Get-NetIPInterface -InterfaceAlias $VPNInterfaceName | Set-NetIPInterface -InterfaceMetric 5001 Once that's been completed open WSL and you should be good to go, unless there is something else causing further issues that I had not experienced. I hope this helps, as we spent several days attempting to track down the cause.
Edit: Be sure if you have "Ubunut/WSL" set as your default profile in Windows Terminal, that you run the script prior to starting WSL. So if Ubuntu/WSL is your default, set your default to PowerShell, or switch over to PowerShell, run the command wsl --shutdown, then execute the above script, then reopen Ubuntu/WSL.
I believe this is fixed with the latest builds and this issue can be closed.
My issue was my anti-virus firewall. I disabled it and WSL 2 network was working again. Now, I just need to figure out which exceptions to provide, so I can re-enable my firewall.
Windows Version
Windows WSL Version
>wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
docker-desktop Running 2
docker-desktop-data Running 2
Docker Version (with WSL 2 integration and Kubernetes)
Apart from adding routes and nameservers, Kapersky was causing the issue for me. Stoping it was not working either probably it was making changes to some system files to prevent access to WSL application. I found this to be helpful:
Go to: More Tools -> Manage Application -> Application Control -> Manage Application -> 'your WSL app name' -> click on network(green arrow) -> Change value to allow.
Attaching screen shot of same:
I don't know how to explain why this is yet but i'm searching for answers. When I connect my laptop to internet using Ethernet through USB-C (a docking station) unbuntu loses all internet connections. But if I disable the Ethernet connection it and it switch back to Wi-Fi the internet starts working for ubuntu.
I recently did this fix to get my port binding again but then this internet issue started happening... https://github.com/docker/for-win/issues/3171#issuecomment-572571882
Steps From @samscott89
- Open CMD.exe (windows not wsl) run ipconfig
- Goto 'Ethernet adapter vEthernet (WSL):'
- Copy 'Subnet Mask'
- Goto wsl and run
sudo ifconfig eth0 netmask 'Subnet Mask'
5 Goto cmd and copy ' IPv4 Address'- Goto wsl and run
sudo ip route add default via ' IPv4 Address'
problem is there is no connectivity and ifconfig command not found in wsl.. what to do?
@rakeshraimca Go to net-tools and download binary package of your architecture.
Then in wsl go to /mnt/c/Users/user_name/Downloads (it may be any directory) and execute
sudo dpkg -i net-tools-etc-etc-etc_architecture.deb
After that ifconfig should appear in your system
Steps From @samscott89
- Open CMD.exe (windows not wsl) run ipconfig
- Goto 'Ethernet adapter vEthernet (WSL):'
- Copy 'Subnet Mask'
- Goto wsl and run
sudo ifconfig eth0 netmask 'Subnet Mask'
5 Goto cmd and copy ' IPv4 Address'- Goto wsl and run
sudo ip route add default via ' IPv4 Address'
problem is there is no connectivity and ifconfig command not found in wsl.. what to do?
You probably forgot to add nameserver 'IPv4 Address' to your /etc/resolv.conf in wsl so you don't manage to resolve names to IPs try to ping 8.8.8.8 and check if it works
Just to say that everything seems to be ok, but still no ethernet connectivity, only wifi, after wsl 2 install and normal usage.
- Goto wsl and run
sudo ifconfig eth0 netmask 'Subnet Mask'
ifconfig
is a no-go on some builds until you're able to get internet access and install net-tools
.
I don't know why but disabling Mobile Hotspot fixed it for me.
I'm having the same issue and can't figure out how to fix it. I'm on Windows 20211 dev build using the default Ubuntu release
Went through a bunch of solutions. Nothing worked. Found out the problem was my %temp% folder (C:\Users\username\AppData\Local\Temp) was compressed. I uncompressed it and that fixed it immediately.
Including nameserver 192.168.1.1
in my /etc/resolv.conf
seemed to do the work.
for me the workaround of adding a custom nameserver has been working perfectly for the last couple of months. As of today, I no longer have internet either with or without that workaround. What's changed?
also, why is this ticket 'closed'? Given the number of people responding, it's pretty clear that there is not yet a clear solution or consistent workaround for the issue here.
What happened to my WSL2
Final solution The network manager turned off the secondary router, and then the network manager turned on the secondary router and the wsl2 network worked normally.
我也一样, ipconfig一看 default switch 和 wsl 都是媒体已断开
Uninstalling Docker desktop worked for me. Not a good solution though.
using sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf' after connecting my VPN worked perfectly!
+1 for @erickucl solution.
I just had this problem today. I'm commenting to underline that this is still an ongoing issue.
Windows build: 18363.1139 Docker For windows: v19.03.13 (with WSL2 based engine)
Additional note: I'm using vscode with both WSL2 and docker. (maybe there's a link ?)
I would also like to add myself to the list of the lucky ones. Today I broke all my development environments by installing docker desktop. After removing and rebooting, my development environments work normally again, and I can connect to the internet again.
Went through a bunch of solutions. Nothing worked. Found out the problem was my %temp% folder (C:\Users\username\AppData\Local\Temp) was compressed. I uncompressed it and that fixed it immediately.
This fixed my problem, thank you. I guess problem started after I compressed C drive.
Steps From @samscott89
- Open CMD.exe (windows not wsl) run ipconfig
- Goto 'Ethernet adapter vEthernet (WSL):'
- Copy 'Subnet Mask'
- Goto wsl and run
sudo ifconfig eth0 netmask 'Subnet Mask'
5 Goto cmd and copy ' IPv4 Address'- Goto wsl and run
sudo ip route add default via ' IPv4 Address'
When I run
sudo ifconfig eth0 netmask 'Subnet Mask'
I get this:
SIOCSIFNETMASK: Cannot assign requested address
Here is my Ethernet adapter vEthernet (WSL):
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::2d79:f5d0:cd7f:d47a%71
IPv4 Address. . . . . . . . . . . : 172.26.80.1
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . :
My Windows 10 build is 19042.630. If you need any more info ask me ⬇
Wait It just fixed it self I didn't do a thing
** By far the easiest solution that worked for me!
Turn off Fast Start-Up in the System Settings -> Shut-down Settings. Then reboot. That's it. found the solution here... https://stephenreescarter.net/wsl2-network-issues-and-win-10-fast-start-up/
For me this happens after change my PC internet, I was using Wi-Fi and now I'm using internet cable.
I think I solved this just uninstalling docker, restarting my pc and after that it was working again. So I reinstalled the docker and it was Ok.
following this one works for me. https://github.com/microsoft/WSL/issues/3438#issuecomment-751186376
the only thing that worked for me is https://stackoverflow.com/a/54460886/4740149
First disable systemd-resolved service.
sudo systemctl disable systemd-resolved.service
Stop the service
sudo systemctl stop systemd-resolved.service
Remove the link to /run/systemd/resolve/stub-resolv.conf in /etc/resolv.conf
sudo rm /etc/resolv.conf
Add a manually created resolv.conf in /etc/
sudo vim /etc/resolv.conf
Add your prefered DNS server there
nameserver 208.67.222.222
Version 1909 (OS Build 18363.1139), WSL 2
Nothing worked for me. I can not update Windows since this is a company laptop. I had to go back to WSL 1. I will ping back in a year or so when we get another update from our company IT :(
To elaborate on https://github.com/microsoft/WSL/issues/4275#issuecomment-695068842, Windows Update KB4023057 introduced the possibility to file compression before updates when system is running on low storage.
This update [...] may take steps to free up disk space on your device if you do not have enough disk space to install Windows updates. [...] To help free up disk space, this update may compress files in your user profile directory so that Windows Update can install important updates. When files or folders are compressed, they appear as having two blue arrows overlaid on the icon.
That includes %Appdata% (Local, LocalLow, Roaming) and subsequently %Temp%, if the distro's files are compressed it won't initialize and if %Temp% is compressed, you won't have an internet connection.
To decompress folders (and files inside), right click on folder properties and under advanced uncheck all boxes related to allowing compression and reboot after.
I don't know why but disabling Mobile Hotspot fixed it for me.
This works for me, too. But if I reboot my machine, everything is fine. I can access the network without any trouble even when hotspot is enabled.
Went through a bunch of solutions. Nothing worked. Found out the problem was my %temp% folder (C:\Users\username\AppData\Local\Temp) was compressed. I uncompressed it and that fixed it immediately.
This solved my issue as well, thanks!
Compression likely kicked in after a reboot with low disk space, and apparently that is causing all sorts of problems. Before I encountered the internet problem, I had to solve a similar issue that prevented WSL to start due to a compression of %USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited\LocalState
, which prevented WSL to start. Link to that particular issue for reference.
How is this issue "closed" when it's clearly still a problem for lots of people and there is no definitive fix?
from my perspective, many are reporting this as an issue while the actual root cause isn't the same at all.
I had just to uninstall Docker for Windows, restart and the internet started working again in WSL 2!
this worked for me too after that I reinstalled docker again and it still worked afterwards
I had just to uninstall Docker for Windows, restart and the internet started working again in WSL 2!
this worked for me too after that I reinstalled docker again and it still worked afterwards
even though i restarted my pc yesterday a few times inbetween this, it's not working again today a reinstall of docker might fix the issue for me again but nevertheless this is an absolute nightmare to work with in this state
I had this problem after turning on Astrill VPN. Uninstalling it and rebooting my computer fixed my issue, but I don't know why
** By far the easiest solution that worked for me!
Turn off Fast Start-Up in the System Settings -> Shut-down Settings. Then reboot. That's it. found the solution here... https://stephenreescarter.net/wsl2-network-issues-and-win-10-fast-start-up/
This works for me! Thank you!
Hello all,
For me the issue was happening when I connected to my work's VPN a bit too fast just after starting my computer (I guess I didn't give the wsl2 service enough time to be loaded with correct network settings) At the time WSL 2 internet was working fine only when I disconnected from my work's VPN.
I was able to solve this by disconnecting the VPN then restart LxssManager windows service and reconnect to the VPN again.
To restart this service you can do it from interface: search services, open, right click LxssManager in the service list and restart Or by powershell as admin command line: Get-Service LxssManager | Restart-Service
In my case it was a DNS resolving issue. I edited my /etc/resolv.conf
file deleted all existing lines and added only this one:
nameserver 8.8.8.8
none of this helped but answer on stackoverflow helped
https://stackoverflow.com/a/64057835/1319799
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r
Went through a bunch of solutions. Nothing worked. Found out the problem was my %temp% folder (C:\Users\username\AppData\Local\Temp) was compressed. I uncompressed it and that fixed it immediately.
This fixed my problem, thank you. I guess problem started after I compressed C drive.
Yes, this helps. Thanks a lot.
none of this helped but answer on stackoverflow helped
https://stackoverflow.com/a/64057835/1319799
wsl --shutdown netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns netsh winsock reset shutdown /r
Thanks this works for me too. I'm facing connection issue after downloading github desktop for windows.
My case is a little bit different. When I'm using desktop VPN (Tunn Be), I can't connect to the internet from WSL2 I realize it after turning off the VPN and tried to apt update. Could anyone know what's actually going on?
none of this helped but answer on stackoverflow helped https://stackoverflow.com/a/64057835/1319799
wsl --shutdown netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns netsh winsock reset shutdown /r
That also worked for me.
Just wondering (need time to research) what's the effect of those steps. Some considerations:
1) didn't perform a windows reboot after installing the linux distro (ubuntu20) 2) right after installing the linux distro, DNS resolved fine, but no access to (i.e.) ubuntu repos. (BTW, DNS is configured by default as the WSL gateway, should be the beforehand referred "IPv4 Address" from ipconfig's output >> that will refer the request to your Windows (acting as gateway) and then to your internet router and so on; if changed to 8.8.8.8 you're using google's DNS... in fact reaching the internet). 3) Docker desktop is installed, though never used it. Didn't reinstall or so
Curious if the final "shutdown /r" from stackoverflow was the one that did the trick, may never know.
This happen on almost all official WSL distros (suse, debian, ubuntu) . I have not tried kali yet but i think the result will be the same.
This is the report on ubuntu:
Windows build number: 10.0.18932.1000
What you're doing and what's happening:
sudo apt-get update
What's wrong / what should be happening instead:
apt-get update
again. Host name can be resolved now, but get another error:Try disable firewall, still the same error. I only use window defender, no other antivirus.
I convert my distro back to WSL 1 and every network command work fine. The content of resolv.conf in WSL 1 is surprisingly the same as when I overwrite the one in WSL 2
Expected: commands that require internet work as WSL 1
Strace of the failing command, if applicable:
can't, strace has not been installed yet beacause no internet.(I run strace on debian and got the command not found error, so I think ubuntu doesn't have them pre installed too). The log is quite long (3k+ lines) so I put them in a file: apt-strace.log