Understanding 127.0.0.1 vs. 0.0.0.0
Understanding 127.0.0.1 vs. 0.0.0.0
Oct 17, 2022
·
1 min read
·
140
Words
·
-Views
-Comments
When starting a web service we often bind to
0.0.0.0or127.0.0.1. Both work, but they have different behaviors. Here’s a quick refresher.
Example using Express:
app.listen(conf.server.port, '0.0.0.0', function () {
console.log(`Example app listening on port http://0.0.0.0:${conf.server.port}!`);
});
127.0.0.1
Loopback address. If the service binds here, neither the public IP nor the LAN IP can reach it.
Even if you disconnect from the network,
ping 127.0.0.1still responds because the packets never leave the host.
We often use
localhostwhen binding here. Strictly speaking they’re not the same—localhostis a hostname that typically maps to127.0.0.1via/etc/hosts.
0.0.0.0
- Represents all addresses on the machine (loopback, LAN, WAN). Bind here when you want the service reachable via any of them.
Final Thoughts
Choose deliberately based on exposure. Internal services should bind to 127.0.0.1 to reduce risk.

