0

Here I am running an application on a computer, host=localhost, the application runs on localhost:5000, or 127.0.0.1:5000.

  1. When the computer accesses 127.0.0.0/8, or 127.0.0.0 subnet mask 255.0.0.0, does it refer to itself somehow? That is, I enter 127.0.0.1:5000 into the browser and since it corresponds to the mask 127.0.0.0/8, it refers to itself and receives a response from itself?
  2. If you put host=0.0.0.0, it says that the application is running on a host that is in the local network. That is, before it was launched on the host 127.0.0.1, and now it is launched on, for example, the address 192.168.0.2:5000, subnet mask 255.255.255.0. Why if host=0.0.0.0.0, it starts referring to the local IP address, and not to 0.0.0.0? And also, it turns out that inside his subnet I will refer to his local IP address, and outside this subnet to the public one? That's what I was thinking, why if it runs on 192.168.0.2:5000, then for devices on his subnet they will connect on his local IP, but I connect to it using his public IP, since I'm not on his subnet?
  3. I don't quite understand how the subnet mask works. For example, in the example 192.168.0.1/24 everything is clear, there are 24 units and they will give 192.168.0, and under the last octet will be values from 0 to 255, that is, fix the first three octets, and the last octet is completely free.But if 192.168.11.10/21, there are 16 units, then 5 units, remains then 3 zeros and 8 zeros, as a result, the subnet mask will be 192.168.8.0 and the values will be between 192.168.8.0 to 192.168.15.255. Now I will try to figure out the same logic - 16 units, so the first two octets remain the same, then there are 5 units and one unit in 11, that is 00001011 in binary, is left with one unit and remains 00001000 and the values will be from 00001000 to 00001111. But I am surprised that for 192.168.7.12/24 the values will be from 192.168.0.0 to 192.168.7.255, that is completely different addresses, and I thought that they will be in the same subnet with 192.168.8.11
1
  • 2
    0.0.0.0 is a special address (IN_ADDR_ANY) used to specify "use any assigned address(es)" When you enter 127.0.0.1, you're telling the application to bind that specific address. 0.0.0.0 is not valid as a destination - you can't use that in a URL.
    – Ricky
    Commented May 3 at 2:47

1 Answer 1

2

Localhost usually points to 127.0.0.1 which is the first address of the virtual loopback interface (always connected, infinite bandwidth) with the subnet and address range 127.0.0.0/8. It means (only) this host. 127.0.0.0/8 cannot be routed or accessed via a physical interface.

0.0.0.0 (in this context, when binding a service) is the unspecified address, essentially meaning any address on any interface on this host. That address cannot be used in any other way, neither as source nor as destination in an actual packet.

In a nutshell, binding a service to 127.0.0.1 makes it accessible from this host only. Binding to 0.0.0.0 makes it accessible on any IP address on any interface, physical or virtual.

For the subnet mask question, please refer to How do you calculate the prefix, network, subnet, and host numbers?

Public and private IP addresses are yet another thing. RFC 1918 defines the ranges 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 to be used in private networks only. You can use any of them in any way you like, but you can't use them for communication over the public Internet, without translation or tunneling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.