Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Access Your WSL2 Web Apps from Mobile Devices & LAN

If you use WSL2 (Windows Subsystem for Linux) for web development, you've likely hit this wall: you start a development server (Vite, Next.js, Node, Django, Docker), open http://localhost:3000 on your Windows host, and everything works seamlessly. Then you grab your mobile phone or another device on the same Wi-Fi network to test responsive design or mobile-specific behavior... Connection Refused…

Developing web applications using Windows Subsystem for Linux (WSL2) often requires testing on mobile devices or other devices on the same network. However, standard Windows Firewall rules do not allow incoming traffic into the Hyper-V virtual network where WSL2 operates. This results in connection issues when trying to access your development server from a mobile device or LAN.

The root cause is that WSL2 does not run as a native Windows process, but as a lightweight Hyper-V Virtual Machine. Classic Windows Defender Firewall rules apply to the host OS, not the traffic passing into the Hyper-V network. To allow external network traffic into WSL2, specific Hyper-V firewall rules must be created using `New-NetFirewallHyperVRule`, a process that is not visible in the classic firewall GUI.

An open-source utility script has been created to simplify this process. Here's a clear explanation of the steps to enable WSL2 web apps to be accessed from mobile devices or LAN:

1. Bind your development server to listen on all network interfaces (0.0.0.0) instead of localhost. This is necessary for the server to accept connections from the network.

2. Open the required port in the Hyper-V Firewall. The script provided, `wsl-hyperv-firewall.bat`, automates this process. Run the script with the `add` argument followed by the port number you need to open.

3. Find your Windows local IP address using the `ipconfig` command in PowerShell or Command Prompt. This IP address is needed to access your WSL2 server from your mobile device.

4. Connect to your WSL2 server from your mobile device by entering the local IP address and the port number in the browser's address bar (e.g., `http://192.168.1.150:5173`).

Additional functionality includes listing all active Hyper-V rules created by the script and removing them when testing is complete. The rules are persistent across reboots, so you won't need to re-add them every time you restart your machine.

This solution provides a clean, native Windows solution for allowing mobile or cross-device network testing on your LAN when developing inside WSL2.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Thursday 1 October →