About IP 0.0.0.0 in Django

DjangoIp

Django Problem Overview


We've got a server over which we're running a Django powered site. Since we want to test the site, we're using Django's build-in development server (i.e runserver). But I'm curious about the ip of the following command:

python manage.py runserver 0.0.0.0:80

It results in a running site we can visit using server's ip remotely.
But when using 127.0.0.1 instead:

python manage.py runserver 127.0.0.1:80

No one can visit the site with the sever's ip from another pc.

So why? What does 0.0.0.0 exactly means (Google says it's the default route) ? Why can't 127.0.0.1:80 be accessed remotely?

Django Solutions


Solution 1 - Django

0.0.0.0:80 is a shortcut meaning "bind to all IP addresses this computer supports". 127.0.0.1:80 makes it bind only to the "lo" or "loopback" interface. If you have just one NIC with just one IP address, you could bind to it explicitly with, say, 192.168.1.1:80 (if 192.168.1.1 was your IP address), or you could list all the IPs your computer responds to, but 0.0.0.0:80 is a shortcut for that.

Solution 2 - Django

127.0.0.1 is the loopback interface, also known as localhost; this is an address that is only accessible from the same computer, as nothing actually goes over the network. 0.0.0.0 means "listen on all interfaces", and thus will listen for connections on all IP addresses that machine has (likely only one).

Solution 3 - Django

127.0.0.1 is the local (loopback) ip, not the ip of that computer on the network. To access a server across the network, you'll need to know its' network ip

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZhu TaoView Question on Stackoverflow
Solution 1 - DjangoPaul TomblinView Answer on Stackoverflow
Solution 2 - DjangoBrian CampbellView Answer on Stackoverflow
Solution 3 - DjangoAdam HopkinsonView Answer on Stackoverflow