We often find ourselves in a situation where we need to test our applications outside our comfy localhost
and we try to access from that device and we have an ERROR.
For users like me who used WSL2, I hope this might be helpful.
In Powershell
To check in WSL is running
$ wsl -l -v
Should get an output like this:
NAME STATE VERSION
* Ubuntu Running 2
In order to get our IP address in our Windows
$ ipconfig | findstr /i "ipv4"
Should get an output like this:
IPv4 Address. . . . . . . . . . . : 192.168.1.67
IPv4 Address. . . . . . . . . . . : 172.17.16.1
In order to get our IP address from our Linux machine Windows
$ wsl hostname -I
Should get an output like this:
172.17.30.142
Run one of these example commands commands to map our ports and make them accessible through our network:
One app
$ netsh interface portproxy add v4tov4 listenport=4010 listenaddress=0.0.0.0 connectport=4010 connectaddress=172.17.30.142
Another app
$ netsh interface portproxy add v4tov4 listenport=4020 listenaddress=0.0.0.0 connectport=4020 connectaddress=172.17.30.142
To confirm, please run:
$ netsh interface portproxy show all
Should get an output like this:
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
0.0.0.0 4020 172.17.30.142 4020
0.0.0.0 4010 172.17.30.142 4010
After this configuration, you can access to the app in any device, using:
http://192.168.1.67:4010/
http://192.168.1.67:4020/
The official documentation is here:
Top comments (0)