MicrosoftDocs / WSL

Source code behind the Windows Subsystem for Linux documentation.
https://docs.microsoft.com/windows/wsl
Other
1.88k stars 556 forks source link

WSL Networking guidance seems to make incorrect assumptions about network setup #1832

Closed jasonpolites closed 7 months ago

jasonpolites commented 8 months ago

Documentation Issue

In this page, the guidance suggests that connecting to a process in WSL from Windows is as simple as determining the IP address of the WSL container. This is unlikely to be uniformly true. Indeed, in my own environment, the cat /etc/resolv.conf command (as suggested in the documentation), reveals that the WSL container is located at 172.27.160.1. My Windows PC is on a 192.168.x.x address, with a completely different subnet. There's no way these two things can see each other.

Please provide guidance on how to configure the virtual network adapter in WSL 2 to allow for packets to travel FROM Windows TO WSL (on a given port)

Link to documentation page

https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-windows-networking-apps-from-linux-host-ip

Suggested Improvements

No response

Biswa96 commented 8 months ago

My Windows PC is on a 192.168.x.x address, with a completely different subnet

That's IP is probably for your LAN or WAN interface. WSL creates a virtual network interface in Windows also. See the output of ipconfig command.

jasonpolites commented 8 months ago

This is my Windows LAN interface. My WAN address would be whatever my ISP gives me (I presume).

My primary ethernet (physical) adapter on the PC looks like this:

 IPv4 Address. . . . . . . . . . . : 192.168.1.101
 Subnet Mask . . . . . . . . . . . : 255.255.255.0

The WSL ethernet adapter (virtual) looks like this:

 IPv4 Address. . . . . . . . . . . : 172.27.160.1
 Subnet Mask . . . . . . . . . . . : 255.255.240.0

Now I'm no networking expert, but I don't see these things talking to each other. I tried manually changing the IP on the WSL adapter (via Windows) to be on the same address range and subnet, but didn't work.

craigloewen-msft commented 7 months ago

@jasonpolites we've improved this area by updating the docs to make it clearer, as well as adding mirrored mode which should simplify your networking experience. Thank you for filing this feedback!

https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-windows-networking-apps-from-linux-host-ip:~:text=Obtain%20the%20IP%20address%20of%20your%20host%20machine%20by%20running%20this%20command%20from%20your%20Linux%20distribution%3A%20%60%20ip%20route%20show%20%7C%20grep%20%2Di%20default%20%7C%20awk%20%27%7B%20print%20%243%7D%27