Home / Localhost / WSL localhost not working

WSL localhost not working: open a WSL server from Windows

Fix localhost for WSL2: reach a server in WSL from Windows, turn on mirrored networking, or forward the port to other devices.

In WSL2 your Linux system runs in a small virtual machine with its own address. Windows normally forwards localhost to it, but that can stop working, and other devices on your network cannot reach it by default.

What to do, step by step

  1. In WSL, start your server so it listens on all addresses, for example --host 0.0.0.0 for dev servers, and check it works with curl http://localhost:3000 inside WSL.
  2. On Windows, open http://localhost:3000 in the browser.
  3. If that fails, restart WSL from PowerShell: wsl --shutdown, then open WSL again.
  4. On Windows 11 22H2 or newer, try mirrored networking: add the lines below to %UserProfile%\.wslconfig, run wsl --shutdown, and start again.
  5. To reach WSL from your phone or another computer, forward the port in an administrator PowerShell with the portproxy command below, and allow the port in Windows Firewall.

Commands you can copy

PowerShell: restart all WSL systems
wsl --shutdown
.wslconfig: turn on mirrored networking
[wsl2]
networkingMode=mirrored
PowerShell (administrator): forward port 3000 to WSL
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.20.0.2
PowerShell: show the WSL address to use above
wsl hostname -I

Other causes to check

localhost works in Windows only on one address family
Try http://127.0.0.1:3000. A server bound only to IPv6 or only to IPv4 may not be reached through the forward.
The WSL IP address changes after every restart
This is normal in the default NAT mode. Use mirrored networking, or repeat the portproxy command with the new address from wsl hostname -I.
A VPN breaks it
Some VPN clients change the network rules. Disconnect the VPN, restart WSL and test again.
The server works in WSL but not in Windows
Check the server is not bound to a path-only socket, and that Windows Firewall is not blocking the port.

Questions about WSL localhost not working

What is mirrored networking in WSL?
A mode where WSL shares the network of Windows, so localhost works both ways and other devices can reach WSL services more easily. It needs Windows 11 22H2 or newer.
How do I find the WSL IP address?
Run wsl hostname -I in PowerShell, or hostname -I inside WSL.
Why can my phone not open my WSL server?
In the default mode WSL sits behind Windows. Forward the port with netsh, or use mirrored networking, and allow the port in the firewall.

Updated 2026-10-11

Free tools that help

Related pages