How to proxy port from WSL2 to another device in Wi-Fi network
Learn how to proxy port from WSL2 into external physical network
Assume you have a process which listens on TCP 3000 in WSL2
The process should bind for the host0.0.0.0, not127.0.0.1and notlocalhost. Most times software has a host configuration like--host 0.0.0.0or similar. You can Google "How to set host 0.0.0.0 in Svelte/Vue/React etc".
Run PowerShell From Administrator and type there:
New-NetFirewallRule -DisplayName "Allow WSL2 HTTP Server" -Direction Inbound -Protocol TCP -LocalPort 3000 -Action Allow
In WSL 2 terminal
ip a
Search for inet near eth0 to find your WSL2 IP:
Return to Power Shell and type
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=192.168.217.58
Replace connectaddress with your WSL 2 IP.
To find out address of your PC, write in Power Shell:
ipconfig
Search for Wi-FI adapter and IPv4 address:
On your phone connected to same Wi-FI got to https://192.168.28.246:3000 (change it with your IP)