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
- 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.
- On Windows, open http://localhost:3000 in the browser.
- If that fails, restart WSL from PowerShell: wsl --shutdown, then open WSL again.
- On Windows 11 22H2 or newer, try mirrored networking: add the lines below to %UserProfile%\.wslconfig, run wsl --shutdown, and start again.
- 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
wsl --shutdown[wsl2]
networkingMode=mirrorednetsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.20.0.2wsl hostname -IOther 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.
Free tools that help
- Subnet calculatorEnter an IPv4 address with a prefix or netmask to get the network, broadcast, host range, wildcard mask and usable hosts. Split into subnets.
- Common ports listSearch a list of common TCP and UDP port numbers: SSH 22, HTTP 80, HTTPS 443, MySQL 3306, PostgreSQL 5432 and more, with dev server ports.