Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are 127.0.0.1, 0.0.0.0 and localhost different?

I don't understand the difference between these terms and how they are connected.

I looked at a hosts file on my computer and could see that 127.0.0.1 and localhost are connected but not sure how and I don't know where 0.0.0.0 fits into all this.

I've seen other answers to this question but I'm a newbie and the other answers about loopbacks and meta-addresses weren't easy to follow.

like image 676
j obe Avatar asked Aug 08 '16 16:08

j obe


People also ask

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.

Is loopback address same as localhost?

The loopback address, also called localhost, is probably familiar to you. It is an internal address that routes back to the local system. The loopback address in IPv4 is 127.0. 01.

What is the difference between localhost and IP address?

Localhost is a hostname that refers to the local machine currently making the request. On many computers, localhost is an alias for the IP address 127.0. 0.1. When a computer pings this IP address, it is communicating with itself.

What is the difference between 127.0 0.1 and IP address?

The loopback address is only used by the computer you're on, and only for special circumstances—unlike a regular IP address that transfers files to and from other networked devices. For example, a web server running on a computer can point to 127.0. 0.1 so that the pages run locally and test before it's deployed.


2 Answers

Yes, on your local system localhost does translate into 127.0.0.1, which will always be the IP address of the machine that you are currently using. For example, on your computer accessing 127.0.0.1 (or localhost) will just attempt to open a connection with your own computer (useful if you're hosting a local web server)

Meanwhile, 0.0.0.0 has a different use. On a server or any machine with more than 1 ip address, it can be used to refer to all of the IP addresses that the machine uses. For example, if you create a simple java application with a serverSocket, you may want the server socket to listen for incoming connections on all of the servers IP addresses. You would then set the server socket to listen on 0.0.0.0. Hope this helps!

like image 100
Logan Rodie Avatar answered Sep 27 '22 23:09

Logan Rodie


Any address in the whole 127.0.0.0/8 block will loop sent traffic back inside the computer.

Localhost is normally set to 127.0.0.1, but it could be set on any address in the 127.0.0.0/8 block.

The 0.0.0.0 address really means any IPv4 address.

like image 45
Ron Maupin Avatar answered Sep 27 '22 22:09

Ron Maupin