Difference between 127.0.0.1, localhost, and 0.0.0.0

localhost

First, localhost is a domain name that points to 127.0.0.1; both are the same. If you are using a Mac, you can see this line in the /etc/hosts file.

127.0.0.1     localhost

127.0.0.1

The address 127.0.0.1 is typically assigned to the loopback interface and is used to test the local machine’s TCP/IP protocol stack. The loopback is a special network interface (can be understood as a virtual network card) used for network communication between applications on the local machine. As long as the operating system’s network components are functioning properly, the loopback will work.

0.0.0.0

This IP is equivalent to this in Java, representing the current device’s IP. It can represent all IP addresses of the local machine.

For example, if a tomcat configuration file has the listening IP address set to 0.0.0.0, it means your tomcat server listens on all IP addresses of your machine, and can be accessed through any of those IP addresses.

If your local IP addresses are 192.168.1.10 and 172.16.2.10, then you can access your tomcat via http://192.168.1.10:8080/, http://172.16.2.10:8080/.

If your listening address is set to 192.168.1.10, then access via http://172.16.2.10:8080/ will not be possible.

Local IP

Regarding the local IP, you can understand that your machine has three network cards: one called loopback (this is a virtual network card), another called ethernet (this is your wired network card), and another called wlan (this is your wireless network card).

Your local IP is the IP of your actual network card; specifically, one for wired and one for wireless, while 127.0.0.1 is the IP of the virtual network card called loopback.

192.168.1.1

192.168.1.1 is a Class C IP address and can be any host within a local area network, depending on which device your router assigns this address to.

Original