microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.32k stars 814 forks source link

Can not connect to internet in WSL 2 #4275

Closed Fubuchi closed 4 years ago

Fubuchi commented 5 years ago

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:

Ericksgeo commented 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!

sdhdez commented 4 years ago

@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 a resolv.conf file in /run/resolv didn't fix this issue as it got deleted after invoking wsl --shutdown and restarting Ubuntu. I had to sudo rm /etc/resolv.conf and recreate the file as the gist says.

Thank you, it works for me.

aaronlks commented 4 years ago

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 =)

laerteocj commented 4 years ago

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.

testworksau commented 4 years ago

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.

danieleades commented 4 years ago

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.

localvar commented 4 years ago

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
daveomcd commented 4 years ago

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.

ericis commented 4 years ago

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

image

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)

image

ganesh-k13 commented 4 years ago

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: Annotation 2020-08-16 104712

meatherly commented 4 years ago

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

rakeshraimca commented 4 years ago

Steps From @samscott89

  1. Open CMD.exe (windows not wsl) run ipconfig
  2. Goto 'Ethernet adapter vEthernet (WSL):'
  3. Copy 'Subnet Mask'
  4. Goto wsl and run sudo ifconfig eth0 netmask 'Subnet Mask' 5 Goto cmd and copy ' IPv4 Address'
  5. 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?

MoOFueL commented 4 years ago

@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

yanivps commented 4 years ago

Steps From @samscott89

  1. Open CMD.exe (windows not wsl) run ipconfig
  2. Goto 'Ethernet adapter vEthernet (WSL):'
  3. Copy 'Subnet Mask'
  4. Goto wsl and run sudo ifconfig eth0 netmask 'Subnet Mask' 5 Goto cmd and copy ' IPv4 Address'
  5. 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

maulberto3 commented 4 years ago

Just to say that everything seems to be ok, but still no ethernet connectivity, only wifi, after wsl 2 install and normal usage.

mostlydev commented 4 years ago
  1. 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.

taylankasap commented 4 years ago

I don't know why but disabling Mobile Hotspot fixed it for me.

xrishox commented 4 years ago

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

marcmy commented 4 years ago

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.

banrovegrie commented 4 years ago

Including nameserver 192.168.1.1 in my /etc/resolv.conf seemed to do the work.

danieleades commented 4 years ago

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.

caowent commented 4 years ago

What happened to my WSL2

  1. It turned out to be working normally, but suddenly it was abnormal
  2. Using a proxy works fine
  3. DNS is working normally (use the host command to view)
  4. win ping wsl ok
  5. wsl ping win no response
  6. ping baidu.com shows TTL=1
  7. Restarting the computer does not work
  8. Reinstalling WSL2 is invalid
  9. Restoring network settings is invalid
  10. The following is a screenshot of wireshark capture (wsl ping win)

wsl2

win10

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.

L1yp commented 4 years ago

我也一样, ipconfig一看 default switch 和 wsl 都是媒体已断开

jonyt commented 3 years ago

Uninstalling Docker desktop worked for me. Not a good solution though.

g-berthiaume commented 3 years ago

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 ?)

k1sul1 commented 3 years ago

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.

ajayjarhad commented 3 years ago

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.

ghost commented 3 years ago

Steps From @samscott89

  1. Open CMD.exe (windows not wsl) run ipconfig
  2. Goto 'Ethernet adapter vEthernet (WSL):'
  3. Copy 'Subnet Mask'
  4. Goto wsl and run sudo ifconfig eth0 netmask 'Subnet Mask' 5 Goto cmd and copy ' IPv4 Address'
  5. 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 ⬇

ghost commented 3 years ago

Wait It just fixed it self I didn't do a thing

JohnJohansen-dev commented 3 years ago

** 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/

diegoclair commented 3 years ago

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.

krehwell commented 3 years ago

following this one works for me. https://github.com/microsoft/WSL/issues/3438#issuecomment-751186376

hamaney commented 3 years ago

the only thing that worked for me is https://stackoverflow.com/a/54460886/4740149

armenic commented 3 years ago
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 :(

JCalebBR commented 3 years ago

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.

Dicridon commented 3 years ago

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.

ErwinP commented 3 years ago

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.

alexandermorgan commented 3 years ago

How is this issue "closed" when it's clearly still a problem for lots of people and there is no definitive fix?

TwoXTwentyOne commented 3 years ago

from my perspective, many are reporting this as an issue while the actual root cause isn't the same at all.

FloxD commented 3 years ago

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

FloxD commented 3 years ago

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

andredaherb commented 3 years ago

I had this problem after turning on Astrill VPN. Uninstalling it and rebooting my computer fixed my issue, but I don't know why

RinChanNOWWW commented 3 years ago

** 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!

Hollow1838 commented 3 years ago

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

netdjw commented 3 years ago

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
techsin commented 3 years ago

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 
pdcxs commented 3 years ago

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.

h4r5h1t commented 3 years ago

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.

theverahman commented 3 years ago

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?

ignacioruiz commented 3 years ago

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.