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

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

Open
bobvandevijver opened this issue Jun 4, 2020 · 17 comments
Open

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

bobvandevijver opened this issue Jun 4, 2020 · 17 comments
Labels

Comments

@bobvandevijver
Copy link

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

  • see the virtual IP behave as described in the documentation
  • see the local IP in /etc/resolv.conf (but that breaks DNS resolving at this time)
  • see the local IP in some other file

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

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

thorbon commented Jul 11, 2020

Is there any update on this at all?

Currently i did exactly as described above

  • At first the DNS was broken and i couldnt access the internet at all, but after disabling swap and restarting a few times that finally started working
  • i re-enabled swap and configured "generateResolvConf = true" and the file gets generated as it should with the correct nameserver IP and now i can access the internet, but i cannot access the Windows host at all

Did you ever get this to work?

@bobvandevijver
Copy link
Author

bobvandevijver commented Jul 11, 2020

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

@pnutmath
Copy link

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

@unavaliabl3
Copy link

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

kiview commented Jul 2, 2021

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

martyglaubitz commented Sep 16, 2021

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

Biswa96 commented Sep 16, 2021

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

@tramchamploo
Copy link

Allowed inbound connection in firewall and no luck

@jwfang
Copy link

jwfang commented May 26, 2022

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

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

@herbermqh
Copy link

Microsoft, fack you.

@hinhnhumoi
Copy link

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

@JianhongPan
Copy link

Microsoft, fack you.

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

@baranaltay
Copy link

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests