iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌊
Accessing a server on WSL2 from other devices on the same network
This is a guide on how to access a server running on WSL from another device.
On a Mac, I could access it without any extra steps, but with WSL, you need to set up port forwarding on the Windows side.
Check the WSL IP Address
Check it using ifconfig.
Specifically, the 172.21.171.162 part.
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.21.171.162 netmask 255.255.240.0 broadcast 172.21.175.255
inet6 fe80::215:5dff:fe53:6719 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:53:67:19 txqueuelen 1000 (Ethernet)
RX packets 25699 bytes 10913242 (10.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4954 bytes 2993879 (2.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 109531 bytes 128195327 (128.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 109531 bytes 128195327 (128.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Configure Port Forwarding in PowerShell
*Please run as administrator.
netsh interface portproxy add v4tov4 listenport=3000 connectaddress=[IP checked earlier]
You can check the configured port forwarding with:
netsh interface portproxy show v4tov4
PS C:\WINDOWS\system32> netsh interface portproxy add v4tov4 listenport=3000 connectaddress=172.21.171.162
PS C:\WINDOWS\system32> netsh interface portproxy show v4tov4
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
* 3000 172.21.171.162 3000
This article is cross-posted from my personal blog.
Discussion