2

I've got Ubuntu in WSL 2 running on Windows 10 (Version 10.0.19044 Build 19044) host OS.

Windows Defender Firewall is fully disabled.

What does work

  1. A very basic Express app index.js:

    const express = require('express')
    const app = express()
    const port = 3000
    
    app.get('/', (req, res) => {
      res.send('Hello World!')
    })
    
    app.listen(port, () => {
      console.log(`Example app listening on port ${port}`)
    })
    

    Inside WSL, I run npm init, npm i express and finally node index.js.

    Then in a browser on the host OS I visit http://localhost:3000 and I see "Hello World!".

  2. Other Node apps such as EmberJS:

    npx ember-cli -- new foo
    cd foo/
    npm start
    

    This starts a dev server on port 4200 inside WSL.

    Then in a browser on the host OS I visit http://localhost:4200 and I see a boilerplate app.

What does not work

(of course, I make sure first that ports are available)

  1. Running a Node http-server:

    I start npx http-server -p 3000 inside WSL.

    enter image description here

    I access http://localhost:3000 in the host OS. Despite using the same port and host as before, I see "Connection refused".

    From inside WSL, the page does open (e. g. with links http://localhost:3000).

  2. Running a Python HTTP server:

    I start python3 -m http.server 4200 inside WSL.

    enter image description here

    I access http://localhost:4200 in the host OS. Despite using the same port and host as before, I see "Connection refused".

    From inside WSL, the page does open (e. g. with links http://localhost:4200).

  3. Running headless Chrome with --remote-debugging-port.

    Chrome on the host OS is unable to connect to the headless Chrome in WSL.

What I tried

Neither of these helps:

  1. Rebooting.
  2. wsl --shutdown.
  3. Googling. A lot.

Notes

When I start e. g. npx http-server -p 4200, an entry appears in the Network tab of the Resource Moninor in the host OS. It says port 4200, process wslhost.exe, firewall status "Allowed, not restricted".

enter image description here

Yet, I see this:

enter image description here

UPD 1: I've been 🤯 over it for days, and I see individual attempts pass. Like once I've seen Chrome Inspector connect to the headless Chrome in WSL, twice I've seen http-server serve an index page. It hasn't worked for dozens of attempts, then it suddenly works once, then it stops working again.

At the same time, node index.js with Express and ember serve are 100% reliable and are always accessible from the host OS, even on the same port.

UPD 2: the problem does not happen with IPv6. Adding -a :: to http-server lets me connect reliably over IPv6. So why is IPv4 failing?!

Please help.

3
  • 1
    Good question (although network issues would probably be better on Super User), but please post the text (the first two screenshots) as code-blocks rather than images. This meta answer has some of the reasons why. Thanks! Sep 23, 2022 at 21:57
  • 1
    I wish I had some advice for you; I know you've been struggling for this for a bit. Networking issues on WSL can be tricky. It seems like you are attempting localhost (or the IPv4/v6 equivalent) for each connection, I believe? What happens if you try the WSL2 IP address? That is, the one found with ip addr show eth0? Remember to bind the service to 0.0.0.0 if you do that, but I'm wondering if using the IP vs. localhost will have different results. Sep 27, 2022 at 20:39
  • @NotTheDr01ds, I did try that and it does not make a difference. 😔 Using IPv6 though does, even with localhost (::1). Sep 29, 2022 at 3:25

1 Answer 1

0

This problem was caused by Surfshark VPN, regardless of whether it was connected or not.

Uninstalling Surfshark from the host OS and rebooting resolved my issue.

2
  • So good to hear you got this resolved. Oct 4, 2022 at 12:10
  • So while Surfshark installed you could solve that by providing routes for IPs and ports. Command route.
    – pbies
    Oct 4, 2022 at 17:02

You must log in to answer this question.

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