What is 0.0.0.0 versus localhost

Dave Dash
Dave Dash
Nov 6 · 2 min read

tl;dr 0.0.0.0 tells a server to listen on any available IP address (localhost, 192.168.0.2, or whatever). You can’t connect to http://0.0.0.0/.

Recently I’ve had a few separate instances of people who did not fully understand how the 0.0.0.0 address works and more generally localhost.

With the caveat that I am not a network operator, I’ll explain.

Servers often have the ability to bind or listen on a specific address. For example if you start the the rails web server by default it will say something like:

=> Rails 4.2.4 application starting in development on http://localhost:3000

rails is bound to localhost. localhost on most machines translates to 127.0.0.1 which is a loopback (meaning it connects back to your own computer). So rails will only accept traffic that is coming via that address.

If you have another computer, or a phone and try to go to http://localhost:3000 you will not be able to see your server. Your next strategy might be to look at your address on your LAN. In my case I’m at 192.168.0.2. If you tell rails to bind there, however, you may be able to connect from another computer, but you can no longer enter http://localhost:3000/ on your own computer. Also, if your DHCP lease gets renewed or you go to a coffeeshop http://192.168.0.2/ may not do what you would like.

This is where 0.0.0.0 comes in. This tells your server to listen on any IP addresses available. It’s a wildcard. It might make more sense to think of it as listening on *.*.*.*. It makes sense to receive on any channel, but it doesn’t make sense to connect to every channel. Meaning, putting 0.0.0.0 in your web browser doesn’t make sense.

Dave Dash

Written by

Dave Dash

DadOps 24/7 and DevOps Consultant. Formerly @Pinterest and @Mozilla

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade