Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between starting a server binding to 0.0.0.0 vs 127.0.0.1?

It seems that Rails and Django can both start up the server binding to an IP, either

0.0.0.0, 127.0.0.1, or 192.168.1.2  <-- the last one is my local IP

are there other choices? It seems that 0.0.0.0 and 192.168.1.2 can let a Virtual PC on the same machine access this website, while 127.0.0.1 cannot.

However, if it is just the same notebook, using localhost:3000 (for Rails), then it doesn't matter. But either case, 0.0.0.0:3000 won't work.

How does it work? What are the meanings of using 0.0.0.0 vs 127.0.0.1 vs 192.168.1.2?

like image 646
nonopolarity Avatar asked Sep 12 '10 01:09

nonopolarity


People also ask

For what purpose is 127.0 0.1 used for?

Therefore, localhost (127.0. 0.1) is used to establish an IP connection to the same device used by the end-user. Although using 127.0. 0.1 is the most common practice, the IPv4 network standard reserves the range 127.0.

Why 0 and 127 are not used in IP address?

As per Class A Network (2^31 IP address), the valid IP addresses are from 1-126 in the first octet, and 0 & 127 are not used in that class, because starting with 127 has its different kinds of uses.

What is the difference between 127.0 0.1 and localhost?

Hence, the address for localhost has to be looked up or resolved, whereas using 127.0. 0.1 goes directly to that IP address. Another significant difference between localhost and 127.0. 0.1 is how the request is sent.


1 Answers

Binding to 0.0.0.0 means to listen to all interfaces.

Binding to 127.0.0.1 means to listen to the loopback interface.

like image 120
Dan Avatar answered Nov 13 '22 06:11

Dan