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.
127.0.0.1(IPv4) or::1(IPv6) is loopback. Only programs on the same Mac can connect.localhostis the name for it.0.0.0.0(IPv4) or::(IPv6) means every interface at once. Anyone who can reach your Mac over the network can connect.- A specific address, such as
192.168.1.20, means only that interface: in practice, the network it belongs to.
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)
*:3000is a wildcard: every interface. Other devices can connect.127.0.0.1:5432or[::1]:5432is loopback: this Mac only.- An address like
192.168.1.20:8080is reachable from that network.
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:
- Next.js (
next dev) listens on every interface and prints a Network address. Restrict it withnext dev -H 127.0.0.1. - Vite listens on
localhostonly.vite --hostopens it to your network. - Python’s
python3 -m http.serverlistens on every interface. Use--bind 127.0.0.1. - Rails (
rails server) listens onlocalhostin development.-b 0.0.0.0opens it. - Docker:
-p 3000:3000publishes the port on every interface of your Mac. Use-p 127.0.0.1:3000:3000to keep it local. The same goes forports:in a Compose file. - PostgreSQL from Homebrew listens on
localhostby default (listen_addressesinpostgresql.conf).
When to open a server to your network
Listening on every interface is the right choice when you need it:
- Testing a site or API on a real phone or tablet on the same Wi-Fi.
- Showing work to someone in the same room.
- Running a service that a virtual machine or another computer needs to reach.
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
localhostcan resolve to::1(IPv6) before127.0.0.1. A server that only listens on127.0.0.1can then look “down” to a client that tries::1first. Node.js 17 and later changed how it resolveslocalhost, which is a common cause. Using the address127.0.0.1explicitly on both sides avoids it.- Binding to loopback inside a Docker container makes the server unreachable even from your Mac. Inside the container, listen on
0.0.0.0, and restrict the published port on the host side instead, as shown above. - A VPN adds another interface. A wildcard server may be reachable from the VPN’s network too.
- This is about who can connect, not about passwords. A dev server reachable from your network usually has no login and may show debug pages, so treat “reachable” as “readable”.
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:
- This Mac only: the port is bound to
127.0.0.1or::1. - Your network: the port is bound to
0.0.0.0,::or a network address, so other devices on the same Wi-Fi or network can connect.
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.