C.W.K.
Stream
Lesson 11 of 12 · published

Localhost & 0.0.0.0

~15 min · localhost, loopback, 0.0.0.0, binding

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

127.0.0.1 — the loopback that never leaves the box

127.0.0.1 is the loopback address. It always means "this machine, right here." Packets sent to it never touch the network — they loop straight back inside the kernel. The whole 127.0.0.0/8 range (16 million addresses) is reserved for loopback, though only 127.0.0.1 is conventionally used.

localhost is just a hostname mapped to 127.0.0.1 via /etc/hosts. When your dev server prints "running at http://localhost:5173", it's binding to that loopback — only programs on the same machine can connect.

0.0.0.0 — bind to everything

0.0.0.0 is not an address you connect to. It's a special binding address that means "accept connections on any interface this machine has." When a server listens on 0.0.0.0:3000, it accepts traffic via:

  • Loopback (127.0.0.1)
  • Your LAN IP (192.168.1.42)
  • Tailscale IP (100.64.x.x)
  • Any other interface

Versus binding to 127.0.0.1:3000, which only accepts loopback connections — invisible from any other device.

Why this matters constantly

Most dev servers default to one or the other for safety. Vite defaults to localhost-only. FastAPI defaults to localhost-only. If you want to test from a phone or another machine on the LAN, you need to flip the binding to 0.0.0.0 — and accept that anyone else on that network can hit your dev server too.

Code

Bind to loopback vs all interfaces·bash
# Loopback only — only accessible from this Mac
python3 -m http.server 8000 --bind 127.0.0.1

# All interfaces — accessible from any device on the LAN/Tailnet
python3 -m http.server 8000 --bind 0.0.0.0

# Test from another device:
curl http://192.168.1.42:8000

# Vite: --host flips it to 0.0.0.0
npx vite --host

# FastAPI/uvicorn: --host 0.0.0.0
uvicorn main:app --host 0.0.0.0 --port 8000

External links

Exercise

Start a Python server twice — first with --bind 127.0.0.1, then with --bind 0.0.0.0. From a second device on the same Wi-Fi, try curl http://<your-LAN-ip>:8000. The first should fail (connection refused), the second should succeed. That's the practical difference. Stop both servers when done.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.