Some apps in WSL are inaccessible from the host OS while others are accessible on the same ports

Viewed 16

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

Please help.

0 Answers
Related