microsoft / WSL

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

No network connection in any distribution under WSL 2 #5336

Open duncanmmacleod opened 4 years ago

duncanmmacleod commented 4 years ago

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

Try network reset or allow in firewall.

duncanmmacleod commented 4 years ago

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

Try something like ping 216.58.192.164. Does it work?

duncanmmacleod commented 4 years ago
$ ping 216.58.192.164
connect: Network is unreachable
onomatopellan commented 4 years ago

See #4731

duncanmmacleod commented 4 years ago

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

onomatopellan commented 4 years ago

Hard to say. There are more threads with "Network is unreachable" where people tries to solving it in different ways like in https://github.com/microsoft/WSL/issues/4275#issuecomment-511578223

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

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

wi-ry commented 4 years ago

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

Maybe related to https://github.com/microsoft/WSL/issues/5286 ?

duncanmmacleod commented 4 years ago

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

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

habamax commented 4 years ago

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

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

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

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

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

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

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

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

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

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

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

rescenic commented 4 years ago

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

@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

lgtmbro commented 4 years ago

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
  7. ctrl + o and ctrl + x to write a quit
  8. close WSL and reopen, hopefully the issue is fixed :)

Capture

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

BraINstinct0 commented 4 years ago

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?

lgtmbro commented 4 years ago

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?

Sorry, I have updated my solution, you can tell wsl to stop updating that file, which will fix that issue :), also the answer to your question is yes, any eligible DNS should work perfectly :)

JoaoGTBravo commented 4 years ago

A tip that may work in your case if you have wsl2 not working properly, while wsl1 has network and proper VPN access:

  1. Change the WSL version that you are using from wsl2 to wsl1
  2. Run wsl command so the resolv.conf is generated
  3. Change the wsl.conf to: [network] generateResolvConf = false
  4. Now change WSL version back to wsl2
  5. Now when wsl2 is launched it uses the previous resolv.conf file

Note: It seems to me that the problem is that wsl2 is not generating propertly the resolv.conf.

angus-lherrou commented 4 years ago

@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

First option worked perfect for me

onomatopellan commented 4 years ago

@duncanmmacleod Since your ifconfig eth0 didn't show any IP your issue could be #5437. Because of a bug there is no network initialization in WSL2 if swap file can't be created. So try disabling swap file like suggested in that thread and you should get network connection in WSL2.

duncanmmacleod commented 4 years ago

@duncanmmacleod Since your ifconfig eth0 didn't show any IP your issue could be #5437. Because of a bug there is no network initialization in WSL2 if swap file can't be created. So try disabling swap file like suggested in that thread and you should get network connection in WSL2.

@onomatopellan, YES! If I follow the disable swap instructions here, then restart WSL, I have network!

Thank you!

mattrossman commented 4 years ago

I just set up WSL 2 on a fresh installation of Windows on a brand new drive. I can't install anything with apt because the network is unreachable. It's ridiculous that such basic stuff is broken with default settings. I don't want to waste my time trying every possible fix on StackOverflow and GitHub, the Microsoft setup guide should work.

oising commented 4 years ago

Yeah, I upgraded to wsl2 from wsl1, it was fine. Upgraded win10 to 2004, then the nameresolver ip in /etc/resolv.conf was no longer reachable somehow. This looks to be the IP of the hyper-v bridge (172...) -- I changed the resolver to my router's IP and it was fine again. Definitely something b0rked.

ping: google.com: Temporary failure in name resolution

Of course, restarting the lightweight vm caused resolv.conf to be regenerated and it is again broken. I'll try updating /etc/wsl.conf to stop that.

oising commented 4 years ago

setting /etc/wsl.conf to:

[network]
generateResolvConf = false

has no effect, even after restarting the lightweight vm (rebooting host/w10)

What's going on? It keeps regenerating it and points to the hyper-v bridge, which is not responding to DNS requests. Even when my windows 10 firewall is entirely disabled.

PavelSosin-320 commented 4 years ago

No network connection after network reset and manual edition of resolv.conf. Manipulations with resolve.conf can't help if any dns is unreachable. Windows network troubleshooting reports WSL switch error - incorrect IP but can't resolve it. It says that something is wrong with WSL network cables. I suppose that WiFi adapter is not shared correctly between Windows and Linux. My WiFi adapter is recognized as a public network adapter, True? I.e. can't be shared with the bridged guest VM. WiFi adapter sharing WSL switch properties can't be modified using Virtual switch manager now and manual creation of WSL external network switch results in error "The network was not found." It looks like a bug in WSL switch creation or sharing center gap. Maybe WSL adapter has to be bridged with WiFi adapter anyway ????????????????????????????? But stupid Windows 10 Network and sharing center doesn't show this option. NoNetworkSharing

PavelSosin-320 commented 4 years ago

Is it WSL issue at all ???????????? I use Norton antivirus with Norton 360, My Norton, Norton firewall, and all its gadgets. Only when I disabled Norton "smart" firewall completely WSL networking started to work. Unfortunately, every Norton's UI has its independent "Settings". I didn't find any Norton API and when I tried to config security via Windows firewall I got the message that it uses Norton as the provider and it does nothing. Thanks to Norton!

pa-jberanek commented 4 years ago

So, I can confirm a workaround found somewhere else. If I start a WSL2 instance after I start my work (Cisco AnyConnect) VPN, networking inside the WSL2 instance doesn't work at all. Can't ping the gateway, etc.

If you start the WSL2 before you connect the VPN, WSL2 networking works. If you then connect the VPN, WSL2 networking continues to work.

inthevortex commented 4 years ago

@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

Definitely worked for me!!

jplindgren commented 4 years ago

@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

I tried the first option and it worked for me! Thx!

tomparkinson commented 4 years ago

The first option from @rescenic worked for me, although actually I skipped the Windows Network Reset step and it still worked. Thanks for the advice!

inthevortex commented 4 years ago

The first option from @rescenic worked for me, although actually I skipped the Windows Network Reset step and it still worked. Thanks for the advice!

@tomparkinson Can you point out to exactly what you did? Isn't working for me again.

tomparkinson commented 4 years ago

@inthevortex I used the first option that @rescenic posted in this comment which was:

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

Windows Search > Network Reset (I actually skipped this part)

Restart Windows

inthevortex commented 4 years ago

@inthevortex I used the first option that @rescenic posted in this comment which was:

cmd as admin: wsl --shutdown netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns Windows Search > Network Reset (I actually skipped this part) Restart Windows

@tomparkinson I tried doing that without the second last line and the restart, but it's the same for me...

blackliner commented 4 years ago

@rescenic 's method worked for me, everything, including apt and x-server, works again. Thanks!

tomparkinson commented 4 years ago

@inthevortex I used the first option that @rescenic posted in this comment which was:

cmd as admin: wsl --shutdown netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns Windows Search > Network Reset (I actually skipped this part) Restart Windows

@tomparkinson I tried doing that without the second last line and the restart, but it's the same for me...

I think the restart is required - I seem to remember that the output from one or more of the netsh commands said that it would not take effect until after a restart.

inthevortex commented 4 years ago

@inthevortex I used the first option that @rescenic posted in this comment which was:

cmd as admin: wsl --shutdown netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns Windows Search > Network Reset (I actually skipped this part) Restart Windows

@tomparkinson I tried doing that without the second last line and the restart, but it's the same for me...

I think the restart is required - I seem to remember that the output from one or more of the netsh commands said that it would not take effect until after a restart.

@tomparkinson restart made it work again, but let's see if it persists. :P

blackliner commented 4 years ago

Awesome, yesterday it worked, now it is all broken again...

inthevortex commented 4 years ago

Awesome, yesterday it worked, now it is all broken again...

Yes, for me it worked after restart but then I put my laptop to sleep, after that it stopped working.

jamesfreeman959 commented 4 years ago

Also find myself in this position - I'll try the procedure outlined above and report back later - can't reboot until later today. This worked fine when I first upgraded to WSL2, but it's broken now.

XChester commented 4 years ago

So, I can confirm a workaround found somewhere else. If I start a WSL2 instance after I start my work (Cisco AnyConnect) VPN, networking inside the WSL2 instance doesn't work at all. Can't ping the gateway, etc.

If you start the WSL2 before you connect the VPN, WSL2 networking works. If you then connect the VPN, WSL2 networking continues to work.

This was also my problem.