Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No network connection in any distribution under WSL 2 #5336

Open
duncanmmacleod opened this issue Jun 4, 2020 · 222 comments
Open

No network connection in any distribution under WSL 2 #5336

duncanmmacleod opened this issue Jun 4, 2020 · 222 comments
Labels

Comments

@duncanmmacleod
Copy link

Environment

Windows build number: 10.0.19041.0
Your Distribution version: Ubuntu-18.04
Whether the issue is on WSL 2 and/or WSL 1: WSL 2 only (Linux version 4.19.104-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Feb 19 06:37:35 UTC 2020)

Steps to reproduce

I have installed WSL 2 on a new Windows 10 Education machine managed by my employer (university) following the online instructions. Whenever I create a new distribution using WSL version 2 I have no network connection.

duncan@Macleod-XPS:/mnt/c/Users/spxdmm$ ping google.com
ping: google.com: Temporary failure in name resolution
duncan@Macleod-XPS:/mnt/c/Users/spxdmm$ ping 127.0.0.1
connect: Network is unreachable
duncan@Macleod-XPS:/mnt/c/Users/spxdmm$ ifconfig eth0
eth0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:15:5d:a5:38:8b  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

duncan@Macleod-XPS:/mnt/c/Users/spxdmm$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.176.1

Gist of strace here: https://gist.github.com/duncanmmacleod/4a69a363bf990c3a0dead811b22ce6d5

If I use wsl --set-version to roll back the distribution to WSL 1 I get a network connection just fine.

Expected behavior

New distributions on WSL 2 have a working network connection out-of-the-box.

Actual behavior

See above

Thanks, sorry if this is a duplicate of an existing issue (I surely can't be the only one...)

@rescenic
Copy link

rescenic commented Jun 4, 2020

Try network reset or allow in firewall.

@duncanmmacleod
Copy link
Author

Can you be any more specific about how to do either of those things? I'm new to Windows (just migrating back from macOS).

@onomatopellan
Copy link

Try something like ping 216.58.192.164. Does it work?

@duncanmmacleod
Copy link
Author

$ ping 216.58.192.164
connect: Network is unreachable

@onomatopellan
Copy link

See #4731

@duncanmmacleod
Copy link
Author

Ok, looks like this is a duplicate of #4731, is that what you mean @onomatopellan?

@onomatopellan
Copy link

Hard to say. There are more threads with "Network is unreachable" where people tries to solving it in different ways like in #4275 (comment)

It depends of your networking configuration, if you are using some VPN, proxy configuration... Try any of the solutions of those threads and if nothing work the best you can do is post a link to a networking trace so the team can take a look at it.

@duncanmmacleod
Copy link
Author

Thanks @onomatopellan, I don't have any special networking configuration, so will post a tracr using the feedback hub.

@wi-ry
Copy link

wi-ry commented Jun 9, 2020

Try any of the solutions of those threads and if nothing work the best you can do is post a link to a networking trace so the team can take a look at it.

I’ve shared my network trace: https://aka.ms/AA8mo2v

WSL1 works fine, WSL2 does not. Downgrading from WSL2 to WSL1 restores connectivity.

@ericct
Copy link

ericct commented Jun 9, 2020

Maybe related to #5286 ?

@duncanmmacleod
Copy link
Author

Try any of the solutions of those threads and if nothing work the best you can do is post a link to a networking trace so the team can take a look at it.

https://aka.ms/AA8mo2v

@mrausnadian, 'my account doesn't have access to that feedback', can you please summarise the content of that link?

@yooceii
Copy link

yooceii commented Jun 10, 2020

I disabled the Hyper-v feature. The network backs to normal.

@habamax
Copy link

habamax commented Jun 10, 2020

I disabled the Hyper-v feature. The network backs to normal.

How did you do it? If I disable it in windows features then wsl just doesn't run "The request is not supported".

@rescenic
Copy link

@habamax commented on Jun 10, 2020, 7:38 PM GMT+7:

I disabled the Hyper-v feature. The network backs to normal.

How did you do it? If I disable it in windows features then wsl just doesn't run "The request is not supported".

Convert the linux to WSL 1.

@habamax
Copy link

habamax commented Jun 10, 2020

@habamax commented on Jun 10, 2020, 7:38 PM GMT+7:

I disabled the Hyper-v feature. The network backs to normal.

How did you do it? If I disable it in windows features then wsl just doesn't run "The request is not supported".

Convert the linux to WSL 1.

How does it solve the issue with wsl2?

PS, wanted to use wsl2 but it is not ready.

@yooceii
Copy link

yooceii commented Jun 10, 2020

@habamax commented on Jun 10, 2020, 7:38 PM GMT+7:

I disabled the Hyper-v feature. The network backs to normal.

How did you do it? If I disable it in windows features then wsl just doesn't run "The request is not supported".

Convert the linux to WSL 1.

How does it solve the issue with wsl2?

PS, wanted to use wsl2 but it is not ready.

You need to ensure the virtual machine platform is enabled, Check the #4840
Also, make sure the folder of the distro is not compressed or encrypted.

@habamax
Copy link

habamax commented Jun 10, 2020

You need to ensure the virtual machine platform is enabled, Check the #4840
Also, make sure the folder of the distro is not compressed or encrypted.

Well, I can start wsl2 but again there is no internet connection while wsl1 has it.

Anyway, thanks, will continue using wsl1.

@archonic
Copy link

archonic commented Jun 15, 2020

@duncanmmacleod Did you ever solve this? I'm experiencing the same exact issue on 19041.329. I hardly consider using WSL 1 a reasonable solution.

I'm also finding that setting the name server and adding generateResolvConf = false to /etc/wsl.conf has no effect - it gets regenerated after every restart.

@duncanmmacleod
Copy link
Author

@duncanmmacleod Did you ever solve this? I'm experiencing the same exact issue on 19041.329. I hardly consider using WSL 1 a reasonable solution.

No, I submitted the relevant feedback reports to Microsoft and am waiting for a response.

@archonic
Copy link

I've given up on WSL completely. WSL 2 has network adaptor issues and WSL 1 has no docker integration. It's amazing that despite having a fully dockerized environment, I cannot work on Windows.

@majmercado
Copy link

In my case it was the firewall of my antivirus suite that is blocking the connection. Try disabling your antivirus' firewall (or the whole suite) and retry the connection.

The bridge network via your primary physical connection that provides external network access to the WSL guest should work out of the box.

On my case it is norton's firewall that is blocking the connection. It is quite hard to see since there are no notifications that the connection is being blocked. I just added at WSL guest hardware / MAC address via the device trust list.

@pavel-a
Copy link

pavel-a commented Jul 5, 2020

Similar issue here: after upgrade to ver 2004 and wsl 2 - internet (or network) non-functional in any distro.

  • In Ubuntu 18,04 (restored from backup made before update to wsl 2) : DNS resolution fails, but ping to numeric address works. Maybe related to change in resolv.conf behavior.
  • Debian freshly installed from Store after upadte to 2004: even ping to numeric address (8.8.4.4) fails
  • After reinstalling these two distros with --version 1 , dns works in both.

My network config is very simple : plain GB ethernet and (disabled) wi-fi; no any 3rd party network or "security" stuff.

@rescenic
Copy link

rescenic commented Jul 5, 2020

@pavel-a

=============================================================================
FIX WSL2 NETWORKING IN WINDOWS 10
=============================================================================
cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Windows Search > Network Reset

Restart Windows
-----------------------------------------------------------------------------

OR

# Fix network issues
# Delete auto-generated files
[root@PC-NAME user]# rm /etc/resolv.conf || true
[root@PC-NAME user]# rm /etc/wsl.conf || true

# Enable changing /etc/resolv.conf
# Enable extended attributes on Windows drives
[root@PC-NAME user]# cat <<EOF > /etc/wsl.conf
[network]
generateResolvConf = false

[automount]
enabled = true
options = "metadata"
mountFsTab = false
EOF

# Use google nameservers for DNS resolution
[root@PC-NAME user]# cat <<EOF > /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF

Exit Linux WSL

cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Windows Search > Network Reset

Restart Windows

@md-ziauddin
Copy link

@pavel-a

=============================================================================
FIX WSL2 NETWORKING IN WINDOWS 10
=============================================================================
cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Windows Search > Network Reset

Restart Windows
-----------------------------------------------------------------------------

OR

# Fix network issues
# Delete auto-generated files
[root@PC-NAME user]# rm /etc/resolv.conf || true
[root@PC-NAME user]# rm /etc/wsl.conf || true

# Enable changing /etc/resolv.conf
# Enable extended attributes on Windows drives
[root@PC-NAME user]# cat <<EOF > /etc/wsl.conf
[network]
generateResolvConf = false

[automount]
enabled = true
options = "metadata"
mountFsTab = false
EOF

# Use google nameservers for DNS resolution
[root@PC-NAME user]# cat <<EOF > /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF

Exit Linux WSL

cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Windows Search > Network Reset

Restart Windows

Tried, did not work..
when i use ifconfig eth0 there is no ipv4

@hextruda
Copy link

hextruda commented Jul 13, 2020

Hey all,

Please try this if wsl2's internet stops working

  1. sudo nano /etc/resolv.conf
  2. Remove line out the nameserver nameserver 17...
  3. add this new line nameserver 8.8.8.8
  4. ctrl + o and ctrl + x to write a quit
  5. sudo nano /etc/wsl.conf
  6. Paste the following in:
[network]
generateResolvConf = false
  1. ctrl + o and ctrl + x to write a quit
  2. close WSL and reopen, hopefully the issue is fixed :)

Capture

The solution by above by Ziauddin02 resolves it in script form :)

@BraINstinct0
Copy link

BraINstinct0 commented Jul 14, 2020

Hey all,

Please try this if wsl2's internet stops working

  1. sudo nano /etc/resolv.conf
  2. Comment out the nameserver #nameserver 17...
  3. add this new line nameserver 8.8.8.8
  4. ctrl + o and ctrl + x to write a quit
  5. hopefully the issue is fixed :)

Worked! also swapping out 8.8.8.8 to any other (eligible?) DNS seems to work. Though, if I have set my Windows to use a different one, would it cause any problems?

@saifali96
Copy link

Please find attached my solution. I also have a more detailed file if necessary. Install Ubuntu with an IP in external network on WSL2 V2-summary.pdf

Can you please share the more detailed filed @jn-simonnet ? Thanks!

@sakra
Copy link

sakra commented Mar 18, 2023

In my case WSL2 network connectivity was lost after the installation of Windows 10 Update KB5023696 from 2023-03-14. After trying many workarounds mentioned in this thread without success, I converted all my used distros back to WSL1 to restore network connectivity.

@saifali96
Copy link

In my case WSL2 network connectivity was lost after the installation of Windows 10 Update KB5023696 from 2023-03-14. After trying many workarounds mentioned in this thread without success, I converted all my used distros back to WSL1 to restore network connectivity.

I think I was also affected by an updated.

@simsrw73
Copy link

I suffered from this problem on one of my home computers. At the time I reinstalled W11 Pro fresh several times and it was always broke. A few weeks ago, I had to reinstall W11 because I was having issues that I couldn't nail down. After reinstalling W11, I found that the issue was no longer there. I reinstalled a couple more times and WSL always worked.

I used to reinstall Windows constantly years ago as a way of life, to keep my desktop purring. But those days are gone and now I just like to get stuff done, so I hate any solution that involves reinstalling, and I don't like recommending that solution. No way to know if it will work the same for others. But it did work in my case.

@fi11er
Copy link

fi11er commented Mar 23, 2023

Hello! I have the same problem after KB5023696 update. Is there any official microsoft ticket I can watch? Looks like this bug is critical

@ppnoufal
Copy link

Fixes above solve the connectivity issues when you ant to access resources on the Internet. It does not offer a solution when you want WSL to host services, and amongst them when you want to access desktop with X.

The problem is that by default, the internal network is NATted, with a dynamic IP which changes each time WSL is restarted. In order to avoid this, you have to select the external network, and choose the network interface you use to connect to the Inter,et, ethernet or Wifi. Once done, your WSL will have to change the IP address to a fixed IP in the external network by eans of systemd network configuration. I tried that, and it works. If you are interested, I have step by step instructions to achieve it.

Hi, could you please provide me the steps

@wesleysmitthe
Copy link

wesleysmitthe commented Sep 19, 2023

Hi, I just changed the DNS resolver in the file /etc/resolv.conf, and it worked for me.

sudo nano /etc/resolv.conf

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /># [network]
# generateResolvConf = false
nameserver 8.8.8.8

https://learn.microsoft.com/en-us/answers/questions/853140/wsl-2-internet-connectivity-is-gone

@craigloewen-msft
Copy link
Member

Hi folks, we have put out a new update that aims to address networking issues in WSL. In your .wslconfig file you can set experimental.networkingMode=mirrored, as well as some other key settings that should improve your network compatibility! Please try them out and let us know what you think.

More info on this release and the changes can be found here in the blog post.

Please note: You need to be on a Windows Insiders version to use the new networking settings (Any channel of Windows Insiders will do, including release preview). If you see the "These are not supported" messages it means that your current Windows version doesn't have support, and you will need to upgrade. These features will eventually be coming to Windows 11 22H2.

@vishwa3
Copy link

vishwa3 commented Sep 26, 2023

I am also facing this issue and have tried most of the solutions like changing nameserver in resolv.conf as well as commands to reset stuff but no luck - Not only this but previously too faced issues with wsl which resulted in re-imaging the system but it's too time consuming to keep on debugging network errors and try stuff rather than concentrate on my actual tasks - time to convince my lead and manager to maybe move away from Wsl - so many people are facing these issues , but still no clear solution - not everyone is a network wizard to resolve issues like these

@jn-simonnet
Copy link

Given the exchange above, I am publishing what I did to solve the isue. The key is an action in Hyper-V manager to change networking options.
A word of caution : I have not recently verified if this still works. My solution dates back December 2022.

Install Ubuntu with an IP in external network on WSL2 V2-summary.pdf

@Elektronenvolt
Copy link

@vishwa3 - try this - may your Windows Firewall blocks DNS.

#5336 (comment)
New-NetFirewallRule -DisplayName "WSL allow in" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

@vishwa3
Copy link

vishwa3 commented Sep 28, 2023

I am also facing this issue and have tried most of the solutions like changing nameserver in resolv.conf as well as commands to reset stuff but no luck - Not only this but previously too faced issues with wsl which resulted in re-imaging the system but it's too time consuming to keep on debugging network errors and try stuff rather than concentrate on my actual tasks - time to convince my lead and manager to maybe move away from Wsl - so many people are facing these issues , but still no clear solution - not everyone is a network wizard to resolve issues like these

Thanks @Elektronenvolt and @jn-simonnet for your inputs - I managed to resolve the issue . I was on a corporate network with McAfee installed in my system - Raised a ticket with cyber security and got rid of it - The IT team had inadvertently pushed McAfee on my system and soon enough I started facing this issue-once McAfee was gone , WSL2 started pinging again , maybe I was unnecessarily critical of WSL2 though it has caused me issues before - Time to get back to my pending stories now 👍

@marvinhinz
Copy link

@vishwa3 - try this - may your Windows Firewall blocks DNS.

#5336 (comment) New-NetFirewallRule -DisplayName "WSL allow in" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

This solved my issue! Although i did not change anything, the network connectivity just stopped working, i was this close to reinstalling my wsl :D

@vishwa3
Copy link

vishwa3 commented Oct 21, 2023

@vishwa3 - try this - may your Windows Firewall blocks DNS.
#5336 (comment) New-NetFirewallRule -DisplayName "WSL allow in" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

This solved my issue! Although i did not change anything, the network connectivity just stopped working, i was this close to reinstalling my wsl :D

Thanks @marvinhinz - My issue is resolved - please check -
https://github.com/microsoft/WSL/issues/5336#issuecomment-1739761276

image

@craigloewen-msft
Copy link
Member

These new networking features are now available on the latest version of Win11 22H2!

Please make sure you're on the latest build to get these features, you can do that by clicking "Check for Updates" in Windows settings. You can check you have the right build by either ensuring you have KB5031354 installed, or run cmd.exe /c ver and ensure that your build number is 22621.2428 or higher (Including the minor build number which is after the . as this was a backport!)

@keith-horton
Copy link
Member

We have updated the troubleshooting document for name resolution. There are configuration which can break DNS name resolution from a WSL container, and there is a work around for an HNS issue. This information can be found here: https://github.com/MicrosoftDocs/WSL/blob/main/WSL/troubleshooting.md#troubleshooting-dns-in-wsl

@abdullah-bin-hasan
Copy link

Doing these solved my problem:
Open Hyper-V Manager as administrator

Select your pc, open Virtual Switch Manager

Select WSL

Set to external network

Select the network card the traffic runs through

Then login to wsl2 terminal and configure an IP address. E.g.

sudo ip addr flush dev eth0
sudo dhclient eth0

This is where i found it: https://stackoverflow.com/a/62438375/10853017

@jby
Copy link

jby commented Nov 24, 2023

How did this turn into an issue about DNS?
I have the same problem as @duncanmmacleod in the original post.
Windows 10, WSL1, Ubuntu -> works fine
Convert to WSL2 -> No network traffic leaving the Ubuntu install, I don't even get a ping response from the Windows host - the Windows host can ping the WSL2 Ubuntu install though.

@jby
Copy link

jby commented Nov 24, 2023

The reported failures in DNS resolution is a result of the problem - not the cause...

@Elektronenvolt
Copy link

The reported failures in DNS resolution is a result of the problem - not the cause...

Can confirm this statement. In our case Windows Defender blocked incoming DNS for the WSL network adapter. In other cases here VPN clients caused DNS troubles, e.g.

@jansturm1
Copy link

Only solution that worked for me (https://superuser.com/a/1671057/1662386):

Add the following to your <windows_user_profile>/.wslconfig:

[wsl2]
networkingMode=mirrored
Exit your WSL distribution

Run wsl --shutdown from PowerShell then restart WSL

@Kieran-Sears
Copy link

@duncanmmacleod Did you ever solve this? I'm experiencing the same exact issue on 19041.329. I hardly consider using WSL 1 a reasonable solution.

I'm also finding that setting the name server and adding generateResolvConf = false to /etc/wsl.conf has no effect - it gets regenerated after every restart.

I believe you need to include [network] above it, just having generateResolvConf = false doesn't cut it.

@zeroarst
Copy link

Only solution that worked for me (https://superuser.com/a/1671057/1662386):

Add the following to your <windows_user_profile>/.wslconfig:

[wsl2]
networkingMode=mirrored
Exit your WSL distribution

Run wsl --shutdown from PowerShell then restart WSL

I got

wsl: Mirrored networking mode is not supported, falling back to NAT networking

Any idea?

@keith-horton
Copy link
Member

Mirrored Mode requires Windows 11 22H2 and higher. And the optional component "Virtual Machine Platform" is installed.

Thanks!

@InternetPseudonym
Copy link

InternetPseudonym commented May 21, 2024

Mirrored Mode requires Windows 11 22H2 and higher. And the optional component "Virtual Machine Platform" is installed.

Thanks!

oh, nice ... a version-locked feature and the the version it is locked to just so happens to be the most ad-ridden one of all time. I see the marketing department finally took full control. Well. It really "is" time to switch / virtualize / pirate winblows, then. Who would've thought.

@Elektronenvolt
Copy link

Mirrored Mode requires Windows 11 22H2 and higher. And the optional component "Virtual Machine Platform" is installed.
Thanks!

oh, nice ... a version-locked feature and the the version it is locked to just so happens to be the most ad-ridden one of all time. I see the marketing department finally took full control. Well. It really "is" time to switch / virtualize / pirate winblows, then. Who would've thought.

Well, I would call it 'dependency' 🧐But, what is 'version locked' in this case? Don't see it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests