microsoft / WSL

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

Cannot access Windows network port from WSL2 using virtual IP #5338

Open bobvandevijver opened 4 years ago

bobvandevijver commented 4 years ago

Environment

Windows build number: 10.0.19041.0
Your Distribution version: Ubuntu 10.04
Whether the issue is on WSL 2 and/or WSL 1: WSL2 (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 just installed a fresh Ubuntu 20.04 LTS on WSL2 for creating this ticket (I experienced the same problem with my Debian on WSL2, so I downgraded that one back to WSL1 as I needed the functionality).

Make sure to have a webserver running on Windows, and you cannot access it with the IP from /etc/resolv.conf in WSL2, even through that should work according to the docs.

In this case, I created a simply NodeJS server on port 8080, which is listening on 0.0.0.0. It is accessible from the entire LAN on 192.168.1.24 (local IP).

Now, if you want to access it from WSL2, using the nameserver (172.21.48.1 here, or virtual IP) as suggested in the article, it unfortunately does not respond at all. Using localhost doesn't work either (as expected), but using the direct IP address does work.

Below is a screenshot of my test: top-left is the WSL2 Ubuntu, top-right is Powershell on Windows running the actual server. De two browser windows on the bottom are run on the host machine, demonstrating the webserver responds to both localhost and the external IP (external IP access was also tested from another machine on the LAN, that works fine).

image

Expected behavior

I would expect to either

The latter would be useful for scripting.

Actual behavior

Well, it isn't working as I would have hopedπŸ˜„

P.S. While working on this, I also managed to break DNS resolving completely. This was probably related to me resetting the Windows firewall (for testing), as it was fixed after rebooting.

pnutmath commented 4 years ago

I also facing similar issues where as sometimes port open from wsl2 accessible from windows host and sometimes not.. Didn't able to get actual reason anywhere... I have all things at latest version on todays date....

thorbon commented 4 years ago

Is there any update on this at all?

Currently i did exactly as described above

Did you ever get this to work?

bobvandevijver commented 4 years ago

No, I did not get this to work, still using WSL1 at the moment

pnutmath commented 4 years ago

I thought I can use this, but finally end up in dual booting my system as always!

unavaliabl3 commented 4 years ago

You're probably being blocked by the Windows firewall as Ethernet is a "Public" network. Create a new rule in windows firewall settings to allow inbound traffic

check out this answer on https://superuser.com/a/1496354

kiview commented 3 years ago

I adden an inbound rule for my test port (8000 in my case) that should apply for all interfaces and for all types of networks (so including public). Still, I can't access the service from within WSL2 using the IP in /etc/resolv.conf.

I also don't see dropped connections logged by the Windows firewall.

martyglaubitz commented 2 years ago

This is still an issue as to this day. I tried every possible workaround... The big problem is that this is preventing many people from migrating from Docker for Windows to Podman running inside Linux on WSL 2, as they cant test the services in the containers against an application server running on Windows (which you usually do when developing said server).

Downgrading to WSL 1 is also not an option as this causes issues with Podmans File system drivers

Biswa96 commented 2 years ago

You need to allow inbound connection in Windows Firewall for that program which wants to connect with WSL2 side.

tramchamploo commented 2 years ago

Allowed inbound connection in firewall and no luck

jwfang commented 2 years ago

still open after two years and no response from Microsoft ... what a shame

but i found a workaround for this on Windows 10 using Internet Connection Sharing:

  1. right click your host network adapter -> properties -> sharing -> Allow other network users to ... -> choose WSL in dropdown list
  2. you may get a dialog say some warning, click Yes. after this the host can access internet normally but WSL can't
  3. restart, then WSL can access internet, and host can be access via host network adapter's IP in step 1

it's wired the chosen WSL disappear after restart in step 1's properties dialog, but seems have no impact.

NOTE: turn off windows defender firewall when testing

Ameame485 commented 2 years ago

well...I also faced this issue today...

herbermqh commented 1 year ago

Microsoft, fack you.

hinhnhumoi commented 1 year ago

i'm facing this issue too and it's feel so bad

JianhongPan commented 1 year ago

Microsoft, fack you.

Windows was sht, is sht, always will be sh*t

baranaltay commented 5 months ago

You're probably being blocked by the Windows firewall as Ethernet is a "Public" network. Create a new rule in windows firewall settings to allow inbound traffic

check out this answer on https://superuser.com/a/1496354

Tried that, still no luck. This issue still persists.

chanpreetdhanjal commented 5 months ago

Hi. Can you please collect networking logs by following the instructions below? https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#collect-wsl-logs-for-networking-issues

baranaltay commented 5 months ago

I was finally able to connect from a docker container on WSL2 to Windows 10 host. (Docker -> WSL2 -> Windows 10). Here is some insight about how I did it: In my case, I was trying to connect to a gRPC server which was listening "localhost" in windows 10, from a client that was also targeting "localhost" and was inside a docker container on WSL2. So, the setup was looking something like this:

Docker(targets: "localhost") -> WSL2 -> Windows 10 (listens: "localhost")

I changed it to something like this:

Docker(targets: "the IP in /etc/resolv.conf on WSL2") -> WSL2 -> Windows 10 (listens: "0.0.0.0")

And it worked.

It might not applicable in your case but in the end I was able to receive connections from my WSL2 ubuntu instance towards Windows 10 host.

P.S.: I also put the docker container network mode to "host". Meaning it was not in its own sub "docker network".