WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Can not connect to internet in WSL 2

Open ghost opened this issue 7 years ago • 196 comments

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:

  • Windows build number: 10.0.18932.1000

  • What you're doing and what's happening:

    • try to run sudo apt-get update
  • What's wrong / what should be happening instead:

    • Error message:

    Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease Temporary failure resolving 'archive.ubuntu.com' Err:2 http://security.ubuntu.com/ubuntu bionic-security InRelease Temporary failure resolving 'security.ubuntu.com' Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease Temporary failure resolving 'archive.ubuntu.com' Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease Temporary failure resolving 'archive.ubuntu.com' Reading package lists... Done

    • This seem like a dns issue, this is the content of my 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 172.22.64.1

    • Run ipconfig from cmd and overwrite resolv.conf with the dns I get from ipconfig. Run apt-get update again. Host name can be resolved now, but get another error:

    Err:1 http://security.ubuntu.com/ubuntu bionic-security InRelease Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.31), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.24), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out ....

    • Try disable firewall, still the same error. I only use window defender, no other antivirus.

    • I convert my distro back to WSL 1 and every network command work fine. The content of resolv.conf in WSL 1 is surprisingly the same as when I overwrite the one in WSL 2

    • Expected: commands that require internet work as WSL 1

  • Strace of the failing command, if applicable: ~~can't, strace has not been installed yet beacause no internet.~~ (I run strace on debian and got the command not found error, so I think ubuntu doesn't have them pre installed too). The log is quite long (3k+ lines) so I put them in a file: apt-strace.log

ghost avatar Jul 06 '19 02:07 ghost

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.

jameslao avatar Jul 06 '19 07:07 jameslao

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...

lidalve avatar Jul 06 '19 15:07 lidalve

try ifconfig down and up

muhviehstah avatar Jul 08 '19 15:07 muhviehstah

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

heamaral avatar Jul 10 '19 17:07 heamaral

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 avatar Jul 10 '19 17:07 heamaral

The problem happened again. Restarting LxssManager does not resolve.

heamaral avatar Jul 11 '19 04:07 heamaral

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

rich-nahra avatar Jul 13 '19 21:07 rich-nahra

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

benhillis avatar Jul 14 '19 03:07 benhillis

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.

ahmedyarub avatar Jul 15 '19 18:07 ahmedyarub

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.

samscott89 avatar Jul 15 '19 21:07 samscott89

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.

rich-nahra avatar Jul 16 '19 00:07 rich-nahra

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

ghost avatar Jul 16 '19 14:07 ghost

@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

samscott89 avatar Jul 16 '19 14:07 samscott89

@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

ghost avatar Jul 16 '19 15:07 ghost

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

samscott89 avatar Jul 16 '19 15:07 samscott89

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

ghost avatar Jul 16 '19 15:07 ghost

@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 avatar Jul 16 '19 15:07 samscott89

@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.

samscott89 avatar Jul 16 '19 15:07 samscott89

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

heamaral avatar Jul 16 '19 20:07 heamaral

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

benhillis avatar Jul 16 '19 23:07 benhillis