1

I am running Ubuntu 20.04 through WSL2 (Linux version 5.10.16.3-microsoft-standard-WSL2). I am running a react-js application on the WSL installation, and I am able to view the webpage from Windows through the web browser by visiting the IP assigned to my WSL box. (Note: I am not able to view the webpage from Windows when visiting localhost).However, if I try to visit the webpage from any other device on the local network, the webpage won't load.

If I try to ping my WSL IP address from another device on the network, I get 100% packet loss.

I have tried to add a proxy rule through Powershell as suggested on Microsoft's website:

netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=MY.WSL.IP.ADR

This has made no difference. I have also tried to specify that my react app should bind to 0.0.0.0, but that also makes no difference. react-scripts start --host 0.0.0.0

1
  • What build version is your windows? The linked site says on a recent version, localhost (and listening on 0.0.0.0) works, and I can confirm that
    – Panki
    Commented Jun 13, 2022 at 21:04

1 Answer 1

0

You may have two different things going on.

First, let me mention that there are several easier ways to get forwarding working from other devices on the network. I cover them in detail in this answer, but:

  • WSL1 will probably run your React app just fine, and it shares the network with Windows, so it doesn't run into these types of forwarding issues.

  • Using SSH to set up reverse forwarding from Windows back to the WSL2 instance is my preferred method when I can't use WSL1. However, for this to work, you'll still need to resolve the localhost-forwarding issue.

As for your issue at hand:

Considering that localhost-forwarding isn't working since you can't access the site from the Windows host itself via localhost, that sounds like it could be the old "localhost forwarding breaks when hibernating" bug. Exit out of WSL and try (from PowerShell) a:

wsl --shutdown

Then restart WSL and try from the Windows host browser again. If it works, it probably stopped working because either:

  • The system hibernated
  • Or the "Fast Startup" option is set in Windows (which it is by default). Fast Startup uses hibernation as well. It can be turned off in your power management settings in Windows.

Given that you are forwarding to the WSL IP address (so not using localhost for that), however, I'm thinking that part might be due to a firewall rule. Make sure you add a corresponding firewall rule to allow all traffic on that port as well.

2
  • 1
    Switching to a WSL1 installation was the easiest fix for me. From your answer you linked, I made a backup of my WSL install and then converted it.
    – JLCarveth
    Commented Jun 14, 2022 at 11:47
  • @JLCarveth Great to hear! Thanks for confirming. Commented Jun 14, 2022 at 12:36

You must log in to answer this question.

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