LightAtom

What Is localhost?

localhost is the name every computer uses for itself. Developers use it to run websites and databases locally before putting them online.

localhost is the hostname that refers to the computer you're using. It resolves to the loopback addresses 127.0.0.1 (IPv4) and ::1 (IPv6), so traffic to it never leaves the machine. A URL like http://localhost:3000 connects to a program on your own Mac listening on port 3000.

How it works

The hostname localhost resolves to the loopback address 127.0.0.1 or ::1, which reaches your own Mac, such as a dev server or database.

Name, address and port

  • localhost is defined in /etc/hosts and reserved by RFC 6761; browsers also treat it specially.
  • It points to 127.0.0.1 and ::1.
  • The port picks the program: localhost:3000 (a Node or React dev server), :5173 (Vite), :8000 (Python), :5432 (PostgreSQL).

Special treatment in browsers

Browsers treat http://localhost as a secure context, so features that normally require HTTPS (service workers, the clipboard API) work in development.

Why localhost doesn't work

  • Nothing is listening on that port: “connection refused”.
  • IPv4 vs IPv6: the server listens on 127.0.0.1 but the client tried ::1 first, or the other way round.
  • Wrong port, or the app picked another because the port was taken.
  • A broken /etc/hosts file, or a VPN or proxy intercepting it.
  • Testing from a phone: localhost on the phone means the phone. Use the Mac's LAN IP instead.

Examples

$ python3 -m http.server 8000
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
$ curl -sI http://localhost:8000 | head -1
HTTP/1.0 200 OK

On a Mac

dscacheutil -q host -a name localhost shows that it resolves to ::1 and 127.0.0.1. lsof -nP -iTCP:3000 -sTCP:LISTEN shows which program holds a port.

See it in the app

LightAtom's ports view lists every app listening on your Mac, including dev servers on localhost.

Frequently asked questions

What is localhost?

The name for your own computer. It resolves to the loopback address 127.0.0.1 (or ::1), so connections stay on the machine.

What is localhost:8080?

A program on your computer listening on port 8080, often a development web server.

Can other people access my localhost?

No. localhost on their machine means their machine. To share, use your LAN IP and make sure the server listens on all interfaces.

Why is localhost refusing to connect?

Usually nothing is running on that port, or the server is listening on IPv4 while the browser tried IPv6. Check with lsof.

LightAtom team

The people who build LightAtom, a network monitor for macOS.