No internet connection on WSL Ubuntu (Windows Subsystem for Linux)

只谈情不闲聊 提交于 2020-12-01 07:47:36

问题


Recently I installed WSL Ubuntu 18.04 on my Windows machine, but nothing seems to work properly, because I have no internet access.
I tried a few commands and sudo apt update says 'Connection failed' and ping google.com literally takes foreveras you can see in this screenshot: https://i.stack.imgur.com/NXJNx.png

I also checked nano /etc/resolv.conf and made sure that the nameservers are right, completely disabled Kaspersky and its firewall, disabled Hyper-V, reinstalled WSL a few times and even disabled Windows Defender. Nothing helped.

So do you have any ideas what the issue could be here?


回答1:


Open windows cmd in admin mode and type thses commands

  1. netsh winsock reset
  2. netsh int ip reset all
  3. netsh winhttp reset proxy
  4. ipconfig /flushdns
  5. reboot

https://github.com/microsoft/WSL/issues/3438#issuecomment-410518578




回答2:


For me this issue arise when I switch from one network to another. Lets say for example I was working at office wifi and then I went home and start using home wifi. The above https://stackoverflow.com/a/63578387/1409707 answer worked for me. It seems like this is an actual isse, so till Windows comes up with a solution I had to find an easier way to do it every time. I copied the commands and created a bat file, kept it on desktop. So, everytime I switch the wifi connection/network I run the bat file as administrator and restart the system. I hope this helps to someone who is trying to figure out why it is happening and how to know an easy way to fix it,(not a permanent) one though.

create a new .bat file with following contents.

I named my file as networkreset.bat

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r 

everytime you switch the wifi/network run the script as adminstrator and restart.

After restarting internet works on WSL on the connected network.




回答3:


I had ufw installed on WSL2 with debian 10, after removing it and restarting Windows it worked.




回答4:


Copying the recipe that worked for me.
Using WSL 2 on Windows 10.

Solution found at https://github.com/microsoft/WSL/issues/5336#issuecomment-653881695


Steps

  1. Open Powershell or Cmd as Administrator
    and run each of these commands:

    wsl --shutdown
    netsh winsock reset
    netsh int ip reset all
    netsh winhttp reset proxy
    ipconfig /flushdns
    

  2. Hit the Windows Key,
    type Network Reset,
    hit enter.

    You should see this window.
    Click "Reset now".


  3. Restart Windows

If you're lucky, WSL 2 should now be able to sudo apt-get update && sudo apt-get upgrade.


Weird edge case

For me I am still unable to ping sites, but internet seems to work everywhere else in WSL 2.

For instance, ping stackoverflow.com (or pinging any site)
results in "100% packet loss".

However curl --location stackoverflow.com -i
results in a successful response.

And sudo apt-get update && sudo apt-get upgrade now works.


Troubleshooting steps before finding the above recipe:

Hadn't used WSL 2 in months, was trying to sudo apt update from a Debian distro's terminal when I discovered my internet wasn't working.

Spent an hour configuring my WSL's /etc/resolv.conf and /etc/wsl.conf and troubleshooting the auto-config bug (https://github.com/microsoft/WSL/issues/3928). Still didn't work.

Then I found this page. Tried the posted directions. Didn't work.

Finally found this posted solution, and WSL 2 suddenly works perfectly.


Took me hours trying to troubleshoot this, hope this is useful to someone someday.




回答5:


For me, it was an issue with VPN service (NordVPN service) which cause many problems. Just stop its service from services.msc.



来源:https://stackoverflow.com/questions/62314789/no-internet-connection-on-wsl-ubuntu-windows-subsystem-for-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!