ToggleHosts
0.0.0.0 vs 127.0.0.1: What’s the Difference?

0.0.0.0 vs 127.0.0.1: What’s the Difference?

Updated 3 min read

0.0.0.0 vs 127.0.0.1 explained: 127.0.0.1 is loopback-only, while 0.0.0.0 binds to all interfaces. When to use each for local servers, Docker and security.

Manage hosts files without the terminal

ToggleHosts helps you manage environments visually on Windows, macOS, and Linux, with automatic DNS flush and backups.

0.0.0.0 and 127.0.0.1 are not interchangeable: 127.0.0.1 is for connecting, 0.0.0.0 is for listening. 127.0.0.1 is the loopback address reachable only from your own machine. 0.0.0.0 is a special "all interfaces" address used when a server binds a socket, it tells the server to accept connections on every network interface. You connect to a service at 127.0.0.1; you bind a service to 0.0.0.0 (or 127.0.0.1) to choose who can reach it.

0.0.0.0 vs 127.0.0.1 at a glance

Aspect127.0.0.10.0.0.0
MeaningLoopback (this machine only)All local interfaces
Typical useConnecting; private bindingServer binding for external access
Reachable from other devicesNoYes
SecuritySafe by defaultExposes the service
Browser addressYesNot reliably

When to use 127.0.0.1

Bind to 127.0.0.1 when a service should be local only, a dev database, a local API you do not want exposed, or anything sensitive. Other devices on the network cannot reach it, which is the safe default. To connect, use 127.0.0.1 or localhost (note the IPv6 nuance in 127.0.0.1 vs localhost).

When to use 0.0.0.0

Bind to 0.0.0.0 when the server must be reachable from outside the machine: testing a site on your phone over the LAN, or a Docker container whose port must reach the host. Many frameworks default to 127.0.0.1; switch to 0.0.0.0 (e.g. --host 0.0.0.0) to expose it.

The IPv6 equivalent (::1)

On IPv6, the loopback address is ::1, the equivalent of 127.0.0.1. A service may listen on the IPv4 loopback but not on ::1 (or the reverse), which is a common cause of ERR_CONNECTION_REFUSED: the browser resolves localhost to the IPv6 loopback first and gets a connection refused because nothing is bound there. For listening on every interface, the IPv6 wildcard :: plays the same role as 0.0.0.0.

The Docker gotcha

A container that binds its app to 127.0.0.1 listens only inside the container, so docker run -p 8080:8080 appears broken. Bind the app to 0.0.0.0 inside the container so the published port reaches the host. See managing the hosts file with Docker.

Framework examples

Node.js / Express

JAVASCRIPT
// Local only (safe default)
app.listen(3000, '127.0.0.1');

// Reachable from phone on same Wi-Fi
app.listen(3000, '0.0.0.0');

Vite

JAVASCRIPT
// vite.config.js - LAN testing
export default { server: { host: '0.0.0.0', port: 5173 } };

Docker Compose

YAML
services:
  web:
    ports:
      - "8080:8080"
    environment:
      - HOST=0.0.0.0

Inside the container, the app must bind 0.0.0.0, not 127.0.0.1.

Quick decision tree

  1. Only this Mac needs access? → bind 127.0.0.1
  2. Phone/tablet on same network? → bind 0.0.0.0, check firewall
  3. Docker port mapping broken? → app inside container → 0.0.0.0
  4. Browser connection refused on localhost? → check IPv6 ::1 vs 127.0.0.1 in 127.0.0.1 vs localhost

Security reminder

Binding to 0.0.0.0 exposes the service to your whole network. On untrusted Wi-Fi, this can leak a dev server. Prefer 127.0.0.1 unless you specifically need external access, and use friendly local domains for clarity, see the hosts file syntax guide. ToggleHosts makes those local domain mappings easy to manage and toggle.

_Last reviewed: June 2026._

Sources and further reading

Also read127.0.0.1 vs localhost explained
Also readManaging the hosts file with Docker
Share this article

Frequently Asked Questions

127.0.0.1 is the loopback address, reachable only from the same machine. 0.0.0.0 is a wildcard that tells a server to listen on all network interfaces, so it is reachable from other devices.

On a trusted local network it is fine, but it exposes the service to anything that can reach your machine. For local-only development, bind to 127.0.0.1.

Inside a container, binding to 127.0.0.1 only listens within the container. Bind to 0.0.0.0 so the published port is reachable from the host.

On Linux it often maps to localhost, but behavior varies by OS. Use 127.0.0.1 or localhost to connect; use 0.0.0.0 only for binding.

Related Articles