Access Localhost from Your Phone: LAN and WSL2 Troubleshooting
Check a development server through loopback, the computer’s LAN address, then a phone. Diagnose binding, firewall, frontend API URLs, and WSL2 networking.
Opening http://localhost:5173 on a phone connects to the phone itself. To reach a development server on your computer, use the computer’s LAN address and configure the service to accept connections on that interface.
The example below uses Vite on port 5173. Open a development server only on a trusted network and stop it when finished.
Prepare the address
- Connect the devices to a network that permits communication between them. Guest Wi-Fi and managed networks may isolate clients.
- Find the computer’s current Wi-Fi or Ethernet IPv4 address. Use
ipconfigon Windows, network settings on macOS, orip -4 addron Linux. - Choose the real LAN interface rather than an unrelated Docker, VPN, or WSL virtual interface.
- On the phone, open the complete URL, such as
http://192.168.1.20:5173/. Replace the example IP with your own.
Your public internet IP is not needed for this local connection. 0.0.0.0 is a server binding value, not the computer’s destination address on the phone.
Allow LAN connections to Vite
From the project directory:
npm run dev -- --host 0.0.0.0 --port 5173 --strictPort
Check the terminal’s actual address and port. If the port is occupied, identify the listener using the port conflict guide. See Vite’s server.host documentation.
Other frameworks have their own binding options; do not assume every command accepts the same arguments. A phone testing a web app does not require exposing the database directly to the LAN.
Narrow the problem in three steps
| Check from | Example URL | First checks if it fails |
|---|---|---|
| The development computer | http://127.0.0.1:5173/ | Startup logs and actual port |
| The same computer | http://192.168.1.20:5173/ | Loopback-only binding or wrong interface address |
| The phone | http://192.168.1.20:5173/ | Firewall, client isolation, VPN, or network reachability |
Reaching the LAN IP from the computer does not prove the phone’s route works. It narrows the application-side checks. Allow the necessary development process or port through the firewall rather than disabling the firewall entirely.
The page opens but API calls or hot updates fail
JavaScript running on the phone treats fetch('http://localhost:8080/api') as a request to the phone. Use the computer’s reachable backend address with the correct CORS configuration, or a relative frontend URL forwarded by a configured development proxy:
fetch('/api/health');
Your proxy and a backend implementing that path must already exist. The Vite guide shows a proxy configuration. A relative URL does not create an API.
HMR uses WebSocket connections. If the page loads but hot updates fail, inspect the terminal, browser debugging output, and the proxy’s WebSocket support. An HTTPS page requesting an HTTP API can also encounter mixed-content restrictions; see MDN’s explanation.
When the project runs inside WSL2
The default NAT mode adds another network boundary between WSL2 and the Windows LAN interface. Windows reaching a WSL service through localhost does not establish that a phone can reach it through the Windows LAN address.
Check the service binding inside WSL, then access from Windows. Follow Microsoft’s WSL networking guide for the LAN solution supported by your Windows and WSL versions. Supported Windows 11 setups can consider mirrored networking; NAT setups may need forwarding and firewall rules. Do not assume the WSL internal address is directly reachable from a phone.
Check the remaining differences
- Wi-Fi changes or DHCP renewal can change the computer’s IP.
- A loopback-only listener needs a binding change; editing DNS cannot fix the listener.
- A certificate covering only localhost may not match the LAN IP. See the HTTPS guide.
- Stop the service after testing and verify the unused listener is gone.
Related: loopback addresses, Expo debugging, and the port reference.