Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

0

Windows 10’s Windows Subsystem for Linux (WSL) is great. I’m using it as my main go-to development environment for some time now. With the most recent major Creators Update, Microsoft is really trying hard to win some web developers back that left its Windows eco-system decades ago. As Microsoft stated, one of the major benefits for WSL is targeted towards the ever growing web developer community. WSL offers native build tool-chains without ugly hack workarounds for Windows is a huge plus. Most modern stack like Ruby on Rails and Node.js works fairly well under WSL (Creators Update at least).

If you have already using Bash on Ubuntu on Windows (aka WSL) to do web development you will notice that any server instance running inside the Bash by default can only be accessed via localhost:portnumber. It would be OK if all you need is accessing the web app via the host-only method, meaning go to the address bar of the browser and enter http://localhost:8080. If you need to access WSL server instance outside the host Windows 10, you would found out that it’s not accessible. This is not due to a lack of features or support from Windows Subsystem for Linux, but rather Windows 10, the host doesn’t know which port to open for external access. Unlike some application that requests for firewall permissions when running the app the first time, WSL doesn’t prompt the host to allow for a specific port to open when you start a node or rails server inside the Ubuntu on Windows. Perhaps, in the future release, Microsoft would allow WSL to send a signal to the host when a specific port starts to listen inside WSL. Nonetheless, here is how to allow your server to be accessible externally outside Windows 10’s host machine.

Go to Windows Firewall with Advanced Security

2017 07 19 1526 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

Under Inbound Rules add a New Rule

2017 07 19 1531 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

Set rule type as Port.

2017 07 19 1532 600x488 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

Enter a Specific local port your server is running under WSL, in this case, I have port 3000 running my node server.

2017 07 19 1532 001 600x488 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

Under the Action tab, make sure to “Allow the connection”

2017 07 19 1532 002 600x488 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

If you aren’t sure which profile, select all to apply this rule.

2017 07 19 1532 003 600x488 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

Give this rule a descriptive name so it will be easily identifiable under the Firewall settings.

2017 07 19 1533 600x488 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

Once the rule is created, you will be able to find it in the table below.

2017 07 19 1533 001 600x294 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

Now try to access the server hosted inside WSL outside the host Windows 10 machine via hostname or IP address. You should be able to load the web page without any problem.

2017 07 19 1534 2 - Allow Server Running Inside WSL To Be Accessible Outside Windows 10 Host

This is how to access a server running inside WSL outside the host Windows 10 machine. Of course, when your development server port changes you need to either update the rule or create a new rule to accommodate the new port.

LEAVE A REPLY

Please enter your comment!
Please enter your name here