WSL port forwarding

I'm trying to connect to a vite dev server running in WSL from my phone on the same local network, but it does not seem to want to connect some commands I tried to run :
netsh.exe interface portproxy add v4tov4 listenport=5173 connectport=5173 connectaddress=$((wsl hostname -I).Trim())

netsh interface portproxy add v4tov4 listenport=5173 listenaddress=0.0.0.0 connectport=5173 connectaddress=(wsl hostname -I)

netsh advfirewall firewall add rule name="Open Port 5173" dir=in action=allow protocol=TCP localport=5173

netsh interface portproxy add v4tov4 listenport=5173 listenaddress=0.0.0.0 connectport=5173 connectaddress=172.30.240.1
netsh.exe interface portproxy add v4tov4 listenport=5173 connectport=5173 connectaddress=$((wsl hostname -I).Trim())

netsh interface portproxy add v4tov4 listenport=5173 listenaddress=0.0.0.0 connectport=5173 connectaddress=(wsl hostname -I)

netsh advfirewall firewall add rule name="Open Port 5173" dir=in action=allow protocol=TCP localport=5173

netsh interface portproxy add v4tov4 listenport=5173 listenaddress=0.0.0.0 connectport=5173 connectaddress=172.30.240.1
172.30.240.1 is the ip of the WSL instance as reported by ipconfig /all
15 Replies
Rägnar O'ock
Rägnar O'ockOP2w ago
ping @ἔρως content of the .wslconfig file :
[wsl2]
memory=16777216000
swapFile=F:\\WSL\\wsl-swap.vhdx
[wsl2]
memory=16777216000
swapFile=F:\\WSL\\wsl-swap.vhdx
ἔρως
ἔρως2w ago
https://learn.microsoft.com/en-us/windows/wsl/wsl-config <-- try setting networkingMode to something else https://learn.microsoft.com/en-us/windows/wsl/networking <-- also check this try the mirrored mode
Rägnar O'ock
Rägnar O'ockOP2w ago
PS C:\Users\ragnar> wsl.exe --distribution Ubuntu-24.04 hostname -i
127.0.1.1
PS C:\Users\ragnar> wsl.exe --distribution Ubuntu-24.04 hostname -i
127.0.1.1
that doesn't seam right
Rägnar O'ock
Rägnar O'ockOP2w ago
"Port 5173 is in use, trying another one..." well... it did something but not what I wanted...
ἔρως
ἔρως2w ago
yeah, it's something maybe a restart
Rägnar O'ock
Rägnar O'ockOP2w ago
ah it's the proxy settings I've added above let's remove them
Rägnar O'ock
Rägnar O'ockOP2w ago
Yeay it works! (It's mighty broken, but it works)
No description
ἔρως
ἔρως2w ago
and it was the setting i said? to mirror the network?
Rägnar O'ock
Rägnar O'ockOP2w ago
think so
ἔρως
ἔρως2w ago
what do you have in the file?
Rägnar O'ock
Rägnar O'ockOP2w ago
[wsl2]
memory=16777216000
swapFile=F:\\WSL\\wsl-swap.vhdx
networkingMode=mirrored
[wsl2]
memory=16777216000
swapFile=F:\\WSL\\wsl-swap.vhdx
networkingMode=mirrored
ἔρως
ἔρως2w ago
nice
Rägnar O'ock
Rägnar O'ockOP2w ago
(yes that's 16GB of RAM)
ἔρως
ἔρως2w ago
i figured

Did you find this page helpful?