Network guide

Access localhost from phone

Your phone cannot use localhost to reach your computer. Use the computer LAN IP address plus the same port instead.

Fast checklist

  1. 1 Put the phone and computer on the same Wi-Fi network.
  2. 2 Find the computer LAN IP address.
  3. 3 Start the dev server so it accepts network connections when your framework requires it.
  4. 4 Open http://LAN-IP:PORT/ on the phone.
  5. 5 If it fails, check firewall rules and whether the server is bound only to localhost.

Quick diagnostic checks

Find the Mac LAN IP ipconfig getifaddr en0

Use the returned address on the phone, for example http://192.168.1.24:3000/. Do not type localhost on the phone.

Bind the dev server for LAN access npm run dev -- --host 0.0.0.0

Frameworks differ, but the idea is the same: the server must listen beyond the computer-only loopback interface.

Open the LAN URL from the phone http://LAN-IP:PORT/

If this fails while localhost works on the laptop, check Wi-Fi isolation, firewall prompts, VPNs, and the framework host setting.

Live request check

What this page sees

Detecting what the server sees...
Public IP Checking...
Request line Checking...
HTTP request headers
Loading headers...

Sensitive headers such as cookies and authorization tokens are filtered before display.

Why localhost fails on a phone

Localhost always means the device currently making the request. On your phone, localhost means the phone, not your laptop.

The right mental model

Use localhost only on the machine running the server. Use a LAN IP, tunnel, or deployed URL for other devices.

Framework host settings matter

Opening the laptop LAN IP is not enough if the dev server is bound only to localhost. Vite, Next.js, Angular, Flask, Django, and similar tools each have a host option for network access.

  • Use the same port that works on the laptop.
  • Keep phone and laptop on the same non-isolated network.
  • Accept the operating system firewall prompt for the dev server when needed.

Related localhost guides

FAQ

Can 127.0.0.1 on my phone reach my laptop?

No. 127.0.0.1 is also loopback for the current device. Use the laptop LAN IP address instead.

Why does my LAN URL still fail?

The server may be bound only to localhost, the firewall may block inbound traffic, or the phone and computer may be on isolated networks.

What is the fastest way to verify a localhost explanation?

Test the exact host, port, and path in the browser, then check the terminal or service logs. Localhost problems are easiest to solve when the URL and the running process match.

When should I use a LAN IP instead of localhost?

Use a LAN IP when another device, browser profile, virtual machine, or container needs to reach a service running on your computer.

Can a coding assistant give the wrong localhost URL?

Yes. Tutorials and coding assistants often assume a default port. Always compare the suggested URL with the actual URL printed by your local development server.