Accessing WSL2 Server from Mobile/External Devices

This guide explains how to configure WSL2 "Mirror Mode" to allow devices on your local network (like your phone) to access a server running inside WSL2.

1. Prerequisites

2. Configure WSL Mirror Mode

Mirror Mode allows WSL to share the same IP address as your Windows host, making networking much simpler.

  1. Open Windows File Explorer and go to %USERPROFILE% (usually C:\Users\<YourUser>).
  2. Create or edit a file named .wslconfig.
  3. Paste the following configuration:
[wsl2]
networkingMode=mirrored
# Ignore virtual or secondary adapters to force WSL to use your primary network
ignoredInterfaces="Ethernet 3"

Note: Replace "Ethernet 3" with the name of any adapter you want WSL to ignore (as seen in ipconfig).

3. Apply Changes

For WSL to read the new configuration, you must restart it:

  1. Open PowerShell as Administrator.
  2. Run:
    wsl --shutdown
    
  3. Re-open your WSL terminal.

4. Verify the IP Address

In your WSL terminal, run:

ip addr show eth0 | grep inet

The IP address should now match your Windows host's physical network IP (e.g., 192.168.1.136).

5. Windows Firewall Configuration

Even with Mirror Mode, Windows will block incoming traffic from other devices unless you add a rule.

  1. Open Windows Defender Firewall with Advanced Security.
  2. Click Inbound Rules > New Rule...
  3. Select Port > TCP > Specific local ports: 8081.
  4. Select Allow the connection.
  5. Ensure Private is checked (and Public if your network is set to Public).
  6. Name it "WSL Server 8081".

6. Access from Phone

  1. Ensure your server is running in WSL and listening on 0.0.0.0 (not localhost).
  2. On your phone's browser, enter: http://<YOUR_WINDOWS_IP>:8081 (Example: http://192.168.1.136:8081)

Troubleshooting