Skip to content
← All posts

localhost vs 0.0.0.0: who can reach your dev server?

Start next dev and it prints two addresses: Local: http://localhost:3000 and Network: http://192.168.1.20:3000. The second one means your phone, a colleague’s laptop, or anyone else on the same Wi-Fi can open your dev server too. Sometimes that is exactly what you want, for testing on a real device. In a café or at a conference, it may not be.

The difference comes down to the address a server listens on. This post explains what localhost, 127.0.0.1 and 0.0.0.0 mean, how to check what each server on your Mac is listening on, and how to keep a server to your Mac.

What a bind address is

When a program opens a port, it also chooses which network interfaces to listen on. Your Mac has several: the loopback interface, which only exists inside the Mac, plus Wi-Fi, Ethernet and any VPN.

So localhost:3000 and 0.0.0.0:3000 are not two ways of writing the same thing. The first keeps the server on your Mac; the second opens it to your network.

Check what your servers listen on

lsof shows the bind address of every listening port:

lsof -nP -iTCP -sTCP:LISTEN

Look at the NAME column:

node     48213 you  23u IPv6 ... TCP *:3000 (LISTEN)
postgres   912 you   7u IPv4 ... TCP 127.0.0.1:5432 (LISTEN)
Python   50122 you   3u IPv4 ... TCP *:8000 (LISTEN)

To check one port, add it: lsof -nP -iTCP:3000 -sTCP:LISTEN.

Common defaults

Tools don’t agree on a default, and they change between versions, so always check the output above rather than relying on memory. As of this writing:

When to open a server to your network

Listening on every interface is the right choice when you need it:

Turn it on for that session, then go back to loopback. Remember that “your network” is whoever else is on it: at home that is your family’s devices, in a café or hotel it is strangers.

Keep a server on your Mac

The safest fix is to bind to loopback in the tool itself, using the flags above. Then nothing outside your Mac can connect, whatever the network.

The macOS firewall helps too, but it works differently. In System Settings › Network › Firewall, it controls incoming connections per app: when an app starts listening, macOS may ask whether to allow incoming connections (signed apps are often allowed automatically). It doesn’t change what the server binds to, and the firewall is turned off on many Macs. Treat it as a second layer, not as the fix.

Caveats

The faster way: CCToolify

The Ports tool in CCToolify shows the bind address of every listening port as a plain answer in the Who can connect column:

A summary tile counts the ports reachable from your network, so you notice when a dev server is open that shouldn’t be. From the same row you can open HTTP servers in your browser, or stop the process. Ports are read on your Mac, and the list never leaves it.

The Ports guide walks through the rest of the screen. If a port is already taken, see Port 3000 already in use? Find and free it on macOS.