Use mDNS when port forwarding as a workaround to access WSL in local network
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
**Is your feature request related to a problem? Please describe.**
As noted in the official manual [Accessing a WSL 2 distribution from your local area network (LAN)](https://docs.microsoft.com/en-us/windows/wsl/networking#accessing-a-wsl-2-distribution-from-your-local-area-network-lan), we can port forwarding WSL's port in Windows host for other in the local network to access WSL. However, as some issue in this repo pointed out ([#4210 WSL2 Set static ip?](https://github.com/microsoft/WSL/issues/4210), [WSL IP address & Subnet is never deterministic (Constantly changing)](https://github.com/microsoft/WSL/issues/4467)), since WSL's IP address changes frequently, we must rewrite port forward rules each time we restart a WSL instance.
To handle this problem, currently people want a static ip for WSL. However, although this approach can resolve this problem, there is no official standard way to configure this, and there are only some community workaround.
**Describe the solution you'd like**
Since there seemed to be some difficulties to officially support static ip of WSL, I think mDNS may be another way for users in local network to access WSL. mDNS is a technique that the host can self-declare a dns name corresponding to its IP address, and current up-to-date stable Windows 10 and 11 can both recognize such declaration.
Practically speaking, inside WSL, we can install mDNS daemons such as `avahi-daemon`, which declares its domain name to current local network (i.e. WSL network, visible to Windows host, not visible to the real local network). Current Windows have built-in mDNS client and `gethostbyname` can translate mDNS domain name to the IP address successfully without any additional configuration.
As a result, inside Windows host, we can write port forwarding rules with WSL's mDNS domain name without knowing the IP address of WSL instance. After reboot or other things, although WSL's IP address has changed, the port forwarding rules can still successfully forward the packet to right target.
However, currently, port-forwarders such as built-in `netsh` and `nginx` seem not implement mDNS right. If I use mDNS domain name as forward target, sometimes the packet can't be forwarded, and this seems to be a random thing.
So the aim of this issue is to discuss: should it be suggested to use mDNS when port forwarding to access WSL in local network, and if so, are there any Windows port-forwarders which successfully implement such feature?
Contributor guide
Research direction
The issue names no repository files or tests. Start by reviewing the linked WSL LAN manual and referenced issues, then investigate the reported mDNS behavior with Windows port-forwarders such as netsh and nginx. Done would require a decided, supportable recommendation for using mDNS with WSL port forwarding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, nginx
- Domain
- networking, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100