Skip to content

Access webserver hosted on WSL2 from other devices in same network. #9212

Closed

Description

When I host the webserver from windows with ipv4 as its hostname I was able to access the website
from my mobile devices under the same network. But doing this under wsl2 ubuntu doesn't work.

When I try to run django webserver with the ip assigned to wsl2 instance, I cannot access the webserver
even from same windows device. The webserver is accessible only when it runs on 127.0.0.1 . How can I
access my wsl2 webserver from other devices under same network.

I would be very happy if you could provide me with a solution or even better release this feature on next update.

Activity

  1. jack775544 commented on Nov 28, 2022

    @jack775544

    A large range of solutions are discussed in this issue #4150.

    The 2 main approaches are using a TCP proxy on the windows side (docs here), or by setting up a bridge mode adapter (this method is undocumented and experimental).

  2. icflorescu commented on Dec 13, 2022

    @icflorescu

    If you're looking for a quick way (and are familiar with Node.js/npm), simply run npx expose-wsl before starting your server.
    More details here: https://github.com/icflorescu/expose-wsl

  3. diqidoq commented on Oct 6, 2024

    @diqidoq

    If you're looking for a quick way (and are familiar with Node.js/npm), simply run npx expose-wsl before starting your server. More details here: https://github.com/icflorescu/expose-wsl

    This is the best option so far from my point of view in comparison to all solutions provided in the different issues around this topic. A) Because the chance is high that your development environment already has Node(.js) installed, even many IDEs require it for some code and spell checks, etc. And B) It is REALLY doing all by itself. Even installing missing dependencies when running the command first time. I just run the command npx expose-wsl. That's it. The firewall asked me after Apache2 restart to accept the request and: Violá. It took me 5 seconds with WSL2 and Win 11 / Debian to be able to access it from another device... After searching and bugging around for days. This option should be more exposed to researchers, maybe in the Windows/WSL issue queues or on top of WSL README's etc.

    Follow and star the linked project and give your angel on the left shoulder a wave: there is a sponsor link on the project and I would strongly encourage you to click on it. It is really a gift that this is available. It's almost Christmas time ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions