开发者

About IP 0.0.0.0 in Django

开发者 https://www.devze.com 2022-12-09 15:37 出处:网络
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

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 c开发者_开发知识库an 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?


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.


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).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消