0

I'm new to windows 11 (or whatever version), and can't figure out networking:

  • I have a Stable Diffusion server running locally on port 7860

  • I have a nodejs server running on port 3000 (whatever) over WSL2

  • I can open both of them in the browser locally, on windows through http://localhost:{PORT}

  • I can ping the windows IP from my mac and get pongs

I can't, though, access the urls from my browser in my macbook

  • I tried disabling the Windows Firewall completely, to no avail

What can i do to fix this?

8
  • What local address are both servers listening on? Have you tried adding specific Windows Firewall rules instead of disabling it outright? Commented Mar 11, 2023 at 6:17
  • what do you mean by local address? if i'm accessing the IP directly... Commented Mar 11, 2023 at 6:19
  • 1
    There's more than one "the IP" involved here – localhost does not go to the same address as your LAN IP address (it goes to 127.0.0.1 or ::1 instead). Servers can choose to accept connections either at all local addresses, or at only a specific one. Does the nodejs server show a "listening on <address>:<port>" when it starts? If not, find it in netstat -a -n -p tcp and check what address it's on. Commented Mar 11, 2023 at 6:24
  • shows 172.17.219.156:3000 and i can access that address locally on windows, again, not from other machines Commented Mar 11, 2023 at 6:28
  • running netstat -a -n -p tcp couldn't find anything under port 3000, i don't know how to read it... Commented Mar 11, 2023 at 6:32

1 Answer 1

1

172.17.219.156:3000 and i can access that address locally on windows, again, not from other machines

WSL2 runs as a Hyper-V VM, and by default it is placed on a virtual network separate from your physical LAN. The host itself knows where the 172.17.219.x network is, but the rest of your LAN does not.

(Normally the host OS and the WSL2 VM also have their own separate 'localhost's, but WSL automatically forwards all 'localhost' connections from host to listeners on the guest to make it appear as a single system.)

It seems that you can configure WSL2 to use an "external" Hyper-V bridge instead, placing the VM directly in your physical network, as per this GitHub comment:

Example working .wslconfig for localhost:

[wsl2]
# Bridged networking
networkingMode=bridged
vmSwitch=WSL_external
dhcp=true

# Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostforwarding=true

and /etc/wsl.conf

[boot]
systemd=true
[network]
generateResolvConf = false

and /usr/lib/systemd/network/wsl_external.network

[Match]
Name=eth0

[Network]
Description=WSL
DHCP=true

Another approach that I've seen is to use Windows' built-in TCP proxy support via netsh interface portproxy to have the host automatically forward certain connections to the guest.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .