Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AbhinasRegmi opened this issue Nov 25, 2022 · 3 comments
Closed
Labels

Comments

@AbhinasRegmi
Copy link

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.

@jack775544
Copy link

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).

@icflorescu
Copy link

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

@diqidoq
Copy link

diqidoq commented Oct 6, 2024

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
Labels
Projects
None yet
Development

No branches or pull requests

4 participants