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

Can not connect to internet in WSL 2 #4275

Closed
Fubuchi opened this issue Jul 6, 2019 · 182 comments
Closed

Can not connect to internet in WSL 2 #4275

Fubuchi opened this issue Jul 6, 2019 · 182 comments
Labels
network wsl2 Issue/feature applies to WSL 2

Comments

@Fubuchi
Copy link

Fubuchi commented Jul 6, 2019

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

@jameslao
Copy link

jameslao commented Jul 6, 2019

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
Copy link

lidalve commented Jul 6, 2019

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
Copy link

try ifconfig down and up

@heamaral
Copy link

heamaral commented Jul 10, 2019

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

@heamaral
Copy link

heamaral commented Jul 10, 2019

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
Copy link

The problem happened again. Restarting LxssManager does not resolve.

@rich-nahra
Copy link

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

@benhillis
Copy link
Member

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

@ahmedyarub
Copy link

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
Copy link

samscott89 commented Jul 15, 2019

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
Copy link

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
Copy link
Author

Fubuchi commented Jul 16, 2019

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

@samscott89
Copy link

samscott89 commented Jul 16, 2019

@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
Copy link
Author

Fubuchi commented Jul 16, 2019

@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
Copy link

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

@Fubuchi
Copy link
Author

Fubuchi commented Jul 16, 2019

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
Copy link

@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
Copy link

samscott89 commented Jul 16, 2019

@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
Copy link

heamaral commented Jul 16, 2019

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
Copy link
Member

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

@anoopchaurasia
Copy link

anoopchaurasia commented Jul 27, 2019

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
Copy link

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

@pauloscardine
Copy link

pauloscardine commented Jul 31, 2019

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

@tuananh
Copy link

tuananh commented Aug 19, 2019

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
Copy link

tuananh commented Aug 19, 2019

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

@Fubuchi
Copy link
Author

Fubuchi commented Aug 20, 2019

Confirmed, it was fixed in the latest insider build.

@Fubuchi Fubuchi closed this as completed Aug 20, 2019
@psalz
Copy link

psalz commented Aug 20, 2019

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

@tuananh
Copy link

tuananh commented Aug 21, 2019

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?

@kurtfoster
Copy link

This feels hacky but it's working or me. I ran these commands from inside WSL

$ cat /etc/wsl.conf
[network]
generateResolvConf = true
nameserver=192.168.1.1
$ cat fix_resolve.sh
#!/bin/bash

sudo sed -i 's/nameserver.*/nameserver 192.168.1.1/g' /etc/resolv.conf
cat /etc/resolv.conf
$ head -n 2 ~/.bashrc
bash /mnt/c/Users/kurtf/fix_resolve.sh
sudo ntpdate time.windows.com

Now, when I wsl--shutdown, it still works as bashrc in Ubunutu resets resolv.conf. When the laptop goes to sleep and I start the wsl shell, ntupdate runs and gets things back in sync.

@BS-BHARAT
Copy link

In my case it was a DNS resolving issue. I edited my /etc/resolv.conf file deleted all existing lines and added all nameserver which is listed in IPv4 DNS Servers: (under network connection details)
image

@tadam98
Copy link

tadam98 commented Sep 2, 2021

The simple procedure that works is to modify the c:\users%USERPROFILE%.wslconfig file to be:
[wsl2]
memory=8GB
swapFile=0
swap=0

For some reason someone at microsoft changed the name of the swap config parameter.
Stragely, when swapfile is defined. network works like a whistle.

Microsoft: Please decouple swalfile from network. And consider supporting both names for the swap.

@ml-manu
Copy link

ml-manu commented Sep 2, 2021

Hi,

I had the same issue ... i was reading similar issues in many forums.
I am using Windows 10.

This is the solution that worked for me:

  1. First check your ethernet connection for WSL

image

  1. Check out the network status for vEthernet (WSL )

image

For me initially the received was 0 or some low values like 1 or 2 .
TO fix this we have to :

  1. Open Hyper V Manager > Virtual Switch Manager
  2. Select WSL and set the Network to External and choose the appropriate Network adapter that is connected to internet

image

  1. If your are good till now, you should see sent and received packets going up. Like the one in step 2.
    (When i checked out the connection properties > Ip V4 : Ip address and DNS was set to configure automatically)

Remaining fix have to be done in your Linux env. I have Ubuntu 20.04 installed.

  1. Open Ubuntu 20.04

  2. set the network ip address and netmask: sudo ifconfig eth0 <ip_address> netmask <net_mask>
    This ip_address should be same as the IP address you got for WSL Adapter. You can see these values by running an ipconfig /all from cmd
    image

  3. Once this is done, if you try to ping an internal ip address you should be able to reach it, but if you try to ping an external address the request will fail stating that there is no route to host.

  4. We have to add a route to external IPs as follows : sudo ip route add default via
    for me my router ip was 192.168.0.1

  5. Finally we have to update our resolver. But WSL2 automatically regenerates /etc/resolv.conf so we have to disable this first. To do so:
    vi /etc/wsl.conf and put the following content in there:

[network]
generateResolvConf = false

  1. After this, you have to restart the linux system : Open a power shell in windows in admin mode and issue:

wsl --shutdown

This will shutdown all the linux instances

  1. now remove resolve.conf and recreate it with the following content:

rm /etc/resolv.conf
recreate it with the following content

nameserver 202.88.238.3
nameserver 8.8.8.8

  1. Now if u try to ping google.com it should fail (because u have to repeat step 2 , every time u restart ...this is still a WIP for me ;-) , if u know to fix it please share that info) . Once u set the ip and mask properly and ping google.com again. You should get the response.

Thats it! Let me know if it works out for you

@tadam98
Copy link

tadam98 commented Sep 2, 2021

The step of:

rm /etc/resolv.conf
recreate it with the following content ...

Could not be done on my windows 10, As soon as "generateResolvConf = false" is set, the resolve file is not accessible. It is actually a link to /run/resolveconf/resolv.conf which cannot be edited even with sudo.

Thus, the simple change to .wslconfig is suggested as the first attempt. (dont forget to wsl --shutdown and strat again after changing the .wslconf)

PS. on windows 11 insider, the .wslconf file is created with the correct swapfile parameter name at the time of installtion. I guess that on the windows 10, since it was an upgrade from wsl1 to wsl2 and since .wslconf already existed with the old "swap=0" that it was not updated with "swapfile=0".

@nbrugger-tgm
Copy link

Don't forget that the issue is 'closed' and fixed

@maphew
Copy link

maphew commented Sep 30, 2021

My case is a little bit different. When I'm using desktop VPN (Tunn** Be**), I can't connect to the internet from WSL2 I realize it after turning off the VPN and tried to apt update.

I also lost conection to internet from wsl2 after starting Checkpoint VPN client in Windows. Shutting down the vpn client did not restore internet to wsl2, and neither did net stop LxssManager; net start LxssManager from Windows side (note: this terminates any open wsl consoles).

Update: After rebooting Windows access to internet from within wsl2 was not interrupted, regardless of vpn client state. So the initial observation may have just been coincidence.

@wswind
Copy link

wswind commented Oct 12, 2021

I don't know why but disabling Mobile Hotspot fixed it for me.

same problem

@cernuschiflorencia
Copy link

I can not change the mask, I black reinstall my Git, I have no WSL connection. Any recommendation?

@DachuanZhao
Copy link

Any progress ?

@Jkudjo
Copy link

Jkudjo commented Nov 17, 2021

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?

you could run a script

@alekzg
Copy link

alekzg commented Dec 1, 2021

Disconnect from VPN, close WSL and reopen it

@maczamora
Copy link

As @alekzg just disconnect VPN, close WSL and re-open it. I can't believe this hasn't been fixed yet. Anyone want to work on this fix together and get it pushed?

@alexanderluiscampino
Copy link

I can't believe windows... This needs to be fixed, wasted my whole morning on this. A simple VPN disconnect and reboot of WSL fixes it. wth going on here.

@chitinlink
Copy link

I don't have any sort of VPN enabled and I'm getting this.

@valorin
Copy link

valorin commented Dec 27, 2021

Have you tried turning off Fast Start-Up in the System Settings -> Shut-down Settings?
I've written up the instructions here: https://stephenreescarter.net/wsl2-network-issues-and-win-10-fast-start-up/

@mabasic
Copy link

mabasic commented Jan 14, 2022

For anyone still struggling I have found that allowing incoming traffic on the public profile in the firewall instantly makes DNS resolution work in WSL without having to make any changes to /etc/resolv.conf or having to create /etc/wsl.conf file.

Windows Defender Firewall with Advanced Security -> Windows Defender Firewall Properties -> Public Profile -> Inbound Connections set to Allow.

My company uses Firewall to block certain ports which causes this issue. When I set this to allow all inbound connections DNS resolution inside WSL starts working instantly.

@xy-lin
Copy link

xy-lin commented Jan 20, 2022

Windows Defender Firewall with Advanced Security -> Windows Defender Firewall Properties -> Public Profile -> Inbound Connections set to Allow.

This works for me. Many thanks!

@chitinlink
Copy link

I should note that for me what worked was uninstalling Check Point Endpoint Security. Even though the program itself wasn't running, uninstalling it fixed this.

@burberger
Copy link

The discussions on #4139 ended up fixing this for me. If your organization uses any of the security baseline policies that ship with Intune, firewall rules are likely the culprit as they implement a deny all incoming rule even for local only interfaces.

@janovesk
Copy link

janovesk commented Jan 25, 2022

You need to make sure that traffic from the network interface in your Linux distro inside WSL2 is routed to the WSL virtual network adapter on your Windows host. If it gets routed anywhere else, you don't get any connectivity to anything outside the Linux vm. Check your routes with route print on the Windows host.

VPN connections are notorious for messing that up. I wrote a post about the problem and how you can work around it here: https://janovesk.com/wsl/2022/01/21/wsl2-and-vpn-routing.html

@CubeFlix
Copy link

CubeFlix commented Feb 1, 2022

none of this helped but answer on stackoverflow helped

https://stackoverflow.com/a/64057835/1319799

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

Thanks, that worked for me!

@ahmedshahriar
Copy link

In my case, I disabled Hyper-V then it worked finally!

@pmarcum
Copy link

pmarcum commented Mar 29, 2022

I have questions regarding the potential solution provided. Basically, I don't know which commands get typed within Windows environment using powershell or cmd versus which get typed within the WSL environment. Could you clarify please?

ifconfig eth0 netmask 255.255.240.0 <-- type in powershell/cmd or in the WSL ?

ip route add default via <-- type in powershell/cmd or WSL?

I ask because the ip route command was not recognized by powershell or cmd, and when typed into the WSL (I had to use sudo, so that's also worth mentioning above for us newbies), I get "RTNETLINK answers: File exists"

@lwbaqueros
Copy link

check this solution. It worked for me after trying all the above suggestions.
Answer here.

@lndaquino
Copy link

Same issue when trying to access network from WSL2. I've uninstalled Docker Desktop on Windows end, rebooted, and it´s working again.

@gnusiva
Copy link

gnusiva commented Aug 16, 2022

Step1:
run this command on powershell windows
Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses | Foreach-Object { "nameserver $_" }
Step 2: copy the output of this command
Step 3: go to wsl and type
sudo vi /etc/resolv.conf
Step 4: comment the existing name server and paste the copied lines from step 2
Step 5: save and exit the file.
Step 6: ping the desired domain name and verify the connection.

@itsazzad
Copy link

itsazzad commented Sep 3, 2022

I can ping; I can nslookup.
But neither can download nor upload for the last few days.

@javierportillo
Copy link

Hi! I've been dealing with this problem for a while, I've tried every solution possible with no results.
The only solution that finally fixed it was completely uninstalling Checkpoint VPN, I even tried to stop every service related to Checkpoint but what solved it at the end was uninstalling it. I even had a ping running in the background and as soon as I uninstalled Checkpoint the ping started to respond.

@itsazzad
Copy link

After factory resetting my TP-Link Wireless Router, the problem was solved. Weird!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
network wsl2 Issue/feature applies to WSL 2
Projects
None yet
Development

No branches or pull requests