microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
16.94k stars 799 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:

jameslao commented 5 years ago

I have a similar issue. Strangely it worked when I first convert to WSL2, but no longer works after a reboot.

For me, the windows hosts generates a WSL ethernet card:

    IP: 192.168.112.1
    Mask: 255.255.240.0

For the WSL ubuntu, ifconfig shows this:

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.114.176  netmask 255.255.255.0  broadcast 192.168.114.255
    inet6 fe80::215:5dff:fe2e:c311  prefixlen 64  scopeid 0x20<link>
    ether 00:15:5d:2e:c3:11  txqueuelen 1000  (Ethernet)
    RX packets 379  bytes 37421 (37.4 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 13  bytes 1006 (1.0 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

when I try to use ping 192.168.112.1, it comes back with connect: Network is unreachable.

I feel the problem is with the netmask, but not sure how to deal with it given the DHCP.

lidalve commented 5 years ago

i also have this issue.When i convert the Ubuntu to wsl version 1, it can connect the Internet. So i config the wsl vEthernet card,make it in the same netmask and reboot, but it doesn't work.Now i have removed the vethernet card, and i found it didn't be crearted any more...

muhviehstah commented 5 years ago

try ifconfig down and up

heamaral commented 5 years ago

I'm having this issue too. ifconfig eth0 down and up doesn't solve the problem

heamaral commented 5 years ago

I think the problem is because I had another virtual machine in Hyper-V (Docker For Windows), and there was another network adapter with the name br-25ddfb4f166c and eth0 with the wrong ip. I uninstalled Docker For Windows and restarted the LxssManager (net stop LxssManager, net start LxssManager) service, and now the adapter is working normally. It may be some conflict with adapters from other virtual machines.

heamaral commented 5 years ago

The problem happened again. Restarting LxssManager does not resolve.

rich-nahra commented 4 years ago

Is it possible to inspect WSL2 virtual machine settings? Its not visible in hyper-v console.

benhillis commented 4 years ago

It is not a traditional VM so no. You can see it via hcsdiag.exe and container powershell apis though.

ahmedyarub commented 4 years ago

I had just to uninstall Docker for Windows, restart and the internet started working again in WSL 2! Note that I've uninstalled all virtualization applications last week, except for Hyper-V.

samscott89 commented 4 years ago

I had the same issue too. network unreachable, and nothing can connect.

The following resolved my issues:

# ifconfig eth0 netmask 255.255.240.0
# ip route add default via <WSL ethernet address>    

(For me, ipconfig shows the WSL virtual eth address as 192.168.64.1.


Explanation:

I noticed that my $ ip addr didn't quite match my \>ipconfig:

$ ip addr show eth0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:db:c0:c6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.76.46/24 brd 192.168.76.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:fedb:c0c6/64 scope link tentative
       valid_lft forever preferred_lft forever

versus

 ipconfig                                                                                                                                                                                                                                                                                                                                                                                                                         Windows IP Configuration

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::f513:b32c:60d5:1200%87
   IPv4 Address. . . . . . . . . . . : 192.168.64.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Virtual ethernet has subnet mask 255.255.240.0.

So the first line changes it to the correct subnet mask.

# ifconfig eth0 netmask 255.255.240.0

For the second line, when I ran ip route, I saw:

$ ip route
192.168.64.0/20 dev eth0  proto kernel  scope link  src 192.168.76.46

Which basically means that only the 192.168.64.0/20 range is routable. Hence why network unreachable for a lot of the commands. So the second one simply adds 192.168.64.1 as the default gateway for all routes:

# ip route add default via 192.168.64.1

Where the 192.168.64.1 matches the output of the windows ipconfig command for the WSL ipv4 address.

I don't know if this is the 100% correct approach, but it certainly fixes this issue for me.

rich-nahra commented 4 years ago

It is not a traditional VM so no. You can see it via hcsdiag.exe and container powershell apis though.

Thanks for the info. Anecdotally, it does feel like its related to docker networking.

I seem to have found an acceptable workaround. At login, it takes a while for docker to fully initialize. With that, I added a WSL2 process that uses networking at startup which finishes before docker is initialized. Specifically I'm exporting DISPLAY and loading an X window.

Working so far.

Fubuchi commented 4 years ago

@samscott89 ip route add default via give me a RTNETLINK answers: File exists . How can I make it work?

samscott89 commented 4 years ago

@samscott89 ip route add default via give me a RTNETLINK answers: File exists . How can I make it work?

You might be fine without the second step then. After applying that step, I see:

$ ip route
default via 192.168.64.1 dev eth0
192.168.64.0/20 dev eth0  proto kernel  scope link  src 192.168.76.46

Where 192.168.64.1 should match whatever ipconfig showed as the WSL ip address.

You will probably need (at least) both lines. If the first line is already there, then either you are good to go, or the issue is elsewhere

Fubuchi commented 4 years ago

@samscott89 the ip address match with the ip in ipconfig but I still cannot ping or use curl. Hope MS address this issue asap because it is a blocker issue that prevent many user from trying and testing WSL 2

samscott89 commented 4 years ago

What's the output of ipconfig (from cmd), and ip a and ip route on WSL?

Fubuchi commented 4 years ago

ipconfig :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter
   Physical Address. . . . . . . . . : 00-15-5D-DB-C8-62
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::99bf:aeb5:cdf6:d3d3%47(Preferred)
   IPv4 Address. . . . . . . . . . . : 172.21.176.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 788534621
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-23-A6-3A-23-20-47-47-77-68-96
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1

ip a:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 4a:67:0b:ea:41:95 brd ff:ff:ff:ff:ff:ff
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:97:ad:4d brd ff:ff:ff:ff:ff:ff
    inet 172.21.183.22/16 brd 172.21.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:fe97:ad4d/64 scope link
       valid_lft forever preferred_lft forever

ip route:

default via 172.21.176.1 dev eth0
172.21.0.0/16 dev eth0 proto kernel scope link src 172.21.183.22
samscott89 commented 4 years ago

@samscott89 the ip address match with the ip in ipconfig but I still cannot ping or use curl. Hope MS address this issue asap because it is a blocker issue that prevent many user try and test WSL 2

But yeah, fully agree. It seems I might have lucked out that my problem was actually fixable. There are a ton of related networking problems this build.

samscott89 commented 4 years ago

@Fubuchi The subnet mask looks wrong on yours as well. Should be 255.255.240.0 corresponding to /20, not /16. But I would expect it to work anyway.

heamaral commented 4 years ago

There is another problem I am experiencing in WSL 2, I do not know if it has any relation to this problem but my downloads often stop. Downloads on docker

This also happens when I install some package with apt

benhillis commented 4 years ago

Good call on the subnet mask, I'll get that fixed.

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

For the record, this is now fixed for me on build 18932.

pauloscardine commented 4 years ago

I have a similar issue. Strangely it worked when I first convert to WSL2, but no longer works after a reboot.

For me, the windows hosts generates a WSL ethernet card:

    IP: 192.168.112.1
    Mask: 255.255.240.0

For the WSL ubuntu, ifconfig shows this:

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.114.176  netmask 255.255.255.0  broadcast 192.168.114.255
    inet6 fe80::215:5dff:fe2e:c311  prefixlen 64  scopeid 0x20<link>
    ether 00:15:5d:2e:c3:11  txqueuelen 1000  (Ethernet)
    RX packets 379  bytes 37421 (37.4 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 13  bytes 1006 (1.0 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

when I try to use ping 192.168.112.1, it comes back with connect: Network is unreachable.

I feel the problem is with the netmask, but not sure how to deal with it given the DHCP.

You are right, looks like this is a dupe of https://github.com/Microsoft/WSL/issues/3438

Try this:

$ sudo ifconfig eth0 netmask 255.255.240.0
$ sudo ip route add default via 192.168.112.1

Where 192.168.112.1 and 255.255.240.0 are the IP and netmask you got on the WSL interface (run ipconfig on windows and look for the WSL entry).

tuananh commented 4 years ago

I have a similar issue. Strangely it worked when I first convert to WSL2, but no longer works after a reboot. For me, the windows hosts generates a WSL ethernet card:

    IP: 192.168.112.1
    Mask: 255.255.240.0

For the WSL ubuntu, ifconfig shows this:

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.114.176  netmask 255.255.255.0  broadcast 192.168.114.255
    inet6 fe80::215:5dff:fe2e:c311  prefixlen 64  scopeid 0x20<link>
    ether 00:15:5d:2e:c3:11  txqueuelen 1000  (Ethernet)
    RX packets 379  bytes 37421 (37.4 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 13  bytes 1006 (1.0 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

when I try to use ping 192.168.112.1, it comes back with connect: Network is unreachable. I feel the problem is with the netmask, but not sure how to deal with it given the DHCP.

You are right, looks like this is a dupe of #3438

Try this:

$ sudo ifconfig eth0 netmask 255.255.240.0
$ sudo ip route add default via 192.168.112.1

Where 192.168.112.1 and 255.255.240.0 are the IP and netmask you got on the WSL interface (run ipconfig on windows and look for the WSL entry).

this fixes the issue for me but i have to do that every time i started wsl VM.

is the real fix coming soon?

tuananh commented 4 years ago

ah, i just updated to insider 18963. the issue seems to be fixed in this build.

Fubuchi commented 4 years ago

Confirmed, it was fixed in the latest insider build.

psalz commented 4 years ago

I'm on 18963 and just ran into this issue, got it working with @samscott89's approach.

tuananh commented 4 years ago

I'm on 18963 and just ran into this issue, got it working with @samscott89's approach.

i'm on 18963 and wsl2 and the issue is fixed. are you using wsl1 by any chance?

AiOO commented 4 years ago

I got same issue on 18963.1000, WSL2. And @samscott89's approach works properly.

If you don't have ifconfig command like me, use below commands:

# ip addr  # check if the current address is unmatched
# ip addr del 192.168.89.250/24 dev eth0  # unmatched address of eth0
# ip addr add 192.168.80.250/20 dev eth0  # new matched address
# ip route add default via 192.168.80.1  # address of WSL2 adapter on Windows
simonknoll commented 4 years ago

Having the same issue on Build 18965

frederickding commented 4 years ago

I think there was a regression. 18965 exhibits this issue with a WSL2 instance (openSUSE).

ConradMearns commented 4 years ago

Having issues, 190816-1722 Ubuntu

Fubuchi commented 4 years ago

Because there are some people have this bug in Build 18965 , I will reopen it.

leofabri commented 4 years ago

I'm having the same bug, it's usually fixable issuing these on cmd:

netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

However, it seems to re-appear sometimes. I hope it gets fixed soon

faustot commented 4 years ago

It's still happening on Build 18965 using Ubuntu

leofabri commented 4 years ago

@faustot please try to issue the commands you see above and reboot your system

CarneyC commented 4 years ago

@leofabri I tried issuing the commands and rebooting, but it didn't resolve the network issue on my machine.

scardine commented 4 years ago

@faustot please try to issue the commands you see above and reboot your system

Sorry, all due respect this is not good advice: rebooting may give you the illusion of "solving" the problem because the problem itself is intermittent. Also, it does not matter if you issue or not the 4 commands you recommend before rebooting - if you are going to reboot this step is a waste of time.

If there is a mismatch between the Linux and Windows netmask, fixing the netmask and adding a default route (to the Windows IP) on the Linux guest will temporarily fix the problem - at least a reboot is not required. Unfortunately it is not a permanent fix although one can automate it using a script as demonstrated in other threads.

faustot commented 4 years ago

rebooting doesn't help anyways, running these in cmd:

netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns

also had no effect on wsl 2's networking either pre or post reboot

setting the netmask to match the ipconfig netmask for wsl2 doesn't help and setting sudo ip route add default via didn't help either

also to expand on this, i'm trying to apt-get update .. running a ping on a domain works fine

chutzler commented 4 years ago

Seeing the same thing here on 190816-1722. The only way to "permanently" fix is to revert back to WSL1 for now.

craigloewen-msft commented 4 years ago

If you're seeing this error could you help us by taking some networking logs when you're trying to access the internet?

Instructions on how to do so are here. Thanks!

faustot commented 4 years ago

feedback submitted

If you're seeing this error could you help us by taking some networking logs when you're trying to access the internet?

Instructions on how to do so are here. Thanks!

trickymast3r commented 4 years ago

image image

the same here in 18975 - always start with wrong ip address

tharsans commented 4 years ago

I am on 10.0.18970.1005 and I had to do following 3 steps to solve this problem. 1) Set correct subnet mask sudo ifconfig eth0 netmask <Ethernet (WSL) subnet mask)> e.g: sudo ifconfig eth0 netmask 172.22.208.1 2) Set default gateway sudo ip route add default via <Ethernet (WSL) IPv4)> e.g sudo ip route add default via 172.22.208.1 3) Change DNS entry in /etc/resolv.conf with 8.8.8.8

TwoXTwentyOne commented 4 years ago

In my case, I simply edited the /etc/resolve.conf and added my own dns entries and removed the one generated by the vm or whatever.

benhillis commented 4 years ago

Typically /etc/resolv.conf is a symlink to a tmpfs location. In order for the /etc/wsl.conf setting to work, you'll also need to replace the symlink with a regular file.

leninalive commented 4 years ago

My feedback too: https://aka.ms/AA627rw

Wayc0des-Land commented 4 years ago

Today i converted from WSL 1 to WSL 2 I didnt change from /etc/resolv.conf I tried disable firewall from Avast Premium Security and then i can update my ubuntu

But how connect to internet use firewall (Avast)?

Microsoft Windows [Version 10.0.18995.1]

SchoofsEbert commented 4 years ago

Same sort of problem on 18990. Edit: problem is still there in 189950.

My subnet mask and IP route are set correctly automatically.

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::39ac:1623:faa1:5a4e%64
   IPv4 Address. . . . . . . . . . . : 172.19.48.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

And on WSL

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.50.111  netmask 255.255.240.0  broadcast 172.19.63.255
        inet6 fe80::215:5dff:feb4:8c78  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:b4:8c:78  txqueuelen 1000  (Ethernet)
        RX packets 468  bytes 85367 (85.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 142  bytes 11761 (11.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
default via 172.19.48.1 dev eth0
172.19.48.0/20 dev eth0 proto kernel scope link src 172.19.50.111

If I try to ping outside the computer, I can't receive the packets back, but it resolves the ip address.

PING google.com (172.217.20.110) 56(84) bytes of data.
^C
--- google.com ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4167ms

Edit: No other AV or firewall is installed on the system except Windows Security

dpereira2016 commented 4 years ago

Hi guys,

I have the same problem, but I have fixed IP addresses on the interface that is connected to the internet.

So, first I remove the fixed IP addresses on the windows gui (dhcp enabled) and it worked.

Then, I put again my IP addresses and gateway.