I’ve been often asked, why do we sometimes need to specify the IP for a program to be 0.0.0.0 in order to get it to be accessible from machines outsides the network. I shall attempt to answer the question in this post.

What is 127.0.0.1

127.0.0.1 is the loopback address. It means, whatever request is made, send it back to the same machine. When a remote host calls this, they’re actually calling themselves.

What is localhost

localhost is simply a conventional mapping done in the hosts file of the OS. It can be changed. I could ask google.com to point to my loopback address and that would work same.

What is 0.0.0.0

0.0.0.0 is a wildcard for all open routes to the system within the system where the script runs.

When do you face the need to differentiate between them -

We specifically face the problem of differentiating them in Flask/Django/NodeJS applications because these are runtimes which require the user to define which IP (or routes) to listen on. If you’ve ever tried web development on PHP, you’d realize that the localhost web server was accessible using the IP of the computer’s LAN as well from other devices (say your mobile). This is because by default Apache listens on *:80 which essentially means 0.0.0.0:80, as given in its default virtual host configuration file -

# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>  # Notice this
    DocumentRoot "/var/www/html" # OR "C:/xampp/htdocs" for Windows systems with XAMPP installation

    # Other directives here
</VirtualHost>

What did you learn today

Today, in under 3 minutes you learnt a very important difference between the different kind of IP addresses you generally encounter during development and while dealing with networks on the same machine!

I’ll post more on 8th Jan, 2020! Bookmark my site to stay tuned!

About me

I am a web developer turned machine learning explorer who loves mixing and matching various stacks! I lead the team at The Code Foundation and we love solving problems about computer vision and NLP!

Send me a hi on [email protected]