Ref:
- https://learn.microsoft.com/en-us/windows/wsl/networking
- https://superuser.com/questions/1679757/how-to-access-windows-localhost-from-wsl2
- Obtain the IP address of your host machine (Windows) by running this command from your Linux distribution:
cat /etc/resolv.conf
- Copy the IP address following the term: nameserver.
- Add rule to Firewall so that incoming connections to the target Windows port is allowed.
New-NetFirewallRule -DisplayName "<Alias>" -InterfaceAlias "vEthernet (WSL)" -Direction Inbound -Protocol TCP -LocalPort <Win_port> -Action Allow
- Connect to any Windows server using the copied IP address
Alternatively Windows server can be accessed with the host/domain: "$(hostname).local"
Alternatively IP of the Windows server may be accessed from
ip route show | grep -i default | awk '{ print $3}'
Powershell command:
netsh interface portproxy add v4tov4 listenport=<Win_port> listenaddress=0.0.0.0 connectport=<WSL2_port> connectaddress=<WSL2_IP>
Obtain <WSL2_IP> from
wsl hostname -I
To see existing port-forwardings:
netsh interface portproxy show all
To delete a particular port-forwarding:
netsh interface portproxy delete v4tov4 listenport=<port> listenaddress=<IP>