1

I want to access my NextJs dev server running on WSL2 on my local network.

I added port 3000 to firewall rules and tested with telnet and it was not immediately accessible.

After some research I found this document: https://learn.microsoft.com/en-us/windows/wsl/networking

So I ran on my WSL2 instance:

cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.23.16.1

I confirmed the WSL2 IP address is correct by pinging from host machine:

ping 172.23.16.1

Pinging 172.23.16.1 with 32 bytes of data:
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128

Then using that IP to run this command on the windows 11 host from an elevated prompt:

netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.23.16.1

Now I am able to telnet into the windows host on 192.168.0.50:3000 (this is local IP of host) but there is no helo and if I try to access it via web browser I get ERR_EMPTY_RESPONSE

The proxy port appears to be there:

netsh interface portproxy show v4tov4

Listen on ipv4:             Connect to ipv4:

Address         Port        Address         Port
--------------- ----------  --------------- ----------
0.0.0.0         3000        172.23.16.1     3000

I tried adding a few more proxy ports

Listen on ipv4:             Connect to ipv4:

Address         Port        Address         Port
--------------- ----------  --------------- ----------
0.0.0.0         3000        172.23.16.1     3000
192.168.0.50     3000        172.23.16.1     3000
127.0.0.1       3000        172.23.16.1     3000

Still getting ERR_EMPTY_RESPONSE over the LAN. I can connect via telnet to the port so I'm guessing it's something to do with the WSL2 Ubunto 20.04 installation.

I am not sure why I cant access it. There is no firewall active in WSL2

ufw status
Status: inactive

If I try to access localhost:3000 on host machine it works. If I try to access http://192.169.0.50:3000/ on host machine I get the error so there has to be a binding missing somewhere but I don't know where.

How can I debug this?

Guerrilla
  • 13,375
  • 31
  • 109
  • 210
  • You might want to take a look at this. https://stackoverflow.com/questions/61002681/connecting-to-wsl2-server-via-local-network#answer-64986363 – Leo Nov 25 '22 at 03:27

1 Answers1

-1

The docs seem to be incorrect. ipconfig and the resolv.conf seem to show wrong IP address.

To get the correct IP address I needed to use: wsl hostname -I from powershell

Guerrilla
  • 13,375
  • 31
  • 109
  • 210