How to proxy port from WSL2 to another device in Wi-Fi network

Since WSL2 is a VM you cant directly access its ports from LAN, but here we will show you how to workaround it

Ivan Borshchov
Ivan Borshchov
CEO
Jan 21, 2025
How to proxy port from WSL2 to another device in Wi-Fi network
How to proxy port from WSL2 to another device in Wi-Fi network

Assume you have a process which listens on TCP 3000 in WSL2

The process should bind for the host 0.0.0.0, not 127.0.0.1 and not localhost. Most times software has a host configuration like --host 0.0.0.0 or 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:

eth0 adapter inet IP
eth0 adapter inet 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:

WiFI adapter IPv4
WiFI adapter IPv4

On your phone connected to same Wi-FI got to https://192.168.28.246:3000  (change it with your IP)