The difference between 0.0.0.0 and 127.0.0.1

It is recommended to refer to the following two articles to study together: 1. Flask run operating environment, debugger, reloader_Xiao Liuxue Android Blog-CSDN Blog 

" Make the server externally visible " section in

2. Thorough! The difference between 127.0.0.1 and 0.0.0.0 finally understands! _Xiao Liuxue Android Blog-CSDN Blog

1. Summary

1) 0.0.0.0: It represents such a set: all unclear hosts and destination networks

2) 255.255.255.255: Restricted broadcast address , this address cannot be forwarded by routers

3) 127.0.0.1: local address , in Windows system, this address has an alias "Localhost"

2. The difference between 0.0.0.0 and 127.0.0.1

1) 0.0.0.0

        Strictly speaking, 0.0.0.0 is no longer a real IP address. It represents such a set: all unknown hosts and destination networks. "Unclear" here means that there is no specific entry in the local routing table to indicate how to get there. For this machine, it is a "shelter", and all the "three noes" people who don't know will be sent there. If you set the default gateway in the network settings, the Windows system will automatically generate a default route with the destination address 0.0.0.0

2) 255.255.255.255

        Restrict broadcast addresses. For this machine, this address refers to all hosts in this network segment (same broadcast domain). If translated into human language, it should be like this: "Everyone in this room is paying attention!" This address cannot be forwarded by routers

3) 127.0.0.1

        Local machine address, mainly used for testing. In Chinese, it means "myself". On Windows systems, this address has an alias "Localhost". To address such an address, it cannot be sent to a network interface. Packets destined for "127.0.0.1" should never appear on the transport medium unless something goes wrong

3. The difference and use of 127.0.0.1, 0.0.0.0 and local IP address

    First assume that the machine has multiple network cards: eth0:192.168.0.1 eth1:192.168.1.1 lo: 127.0.0.1

0.0.0.0 cannot be pinged, which means all IP addresses of the machine

    Listen to 127.0.0.1 and create a Socket, then use the local address (referring to 192.168.0.1 and 192.168.1.1) to establish a tcp connection unsuccessfully, and vice versa; that is, if the address used for monitoring is 192.168.0.1, you can only use 192.168.0.1 to connect.
    And listen to 0.0.0.0 to create a Socket, then no matter whether you use 127.0.0.1 or the local ip, you can establish a tcp connection, that is, you can connect successfully no matter whether you use 127.0.0.1 or 192.168.0.1 or 192.168.1.1.

        0.0.0.0 can also be realized by binding IP_ADDR_ANY when establishing a tcp connection.

    So here comes the question, must the loopback address be 127.0.0.1?

    Answer: Not necessarily! The loopback address for IPv4 is 127.0.0.1, one of the reserved addresses. Although only one address, 127.0.0.1, is used, addresses 127.0.0.0 through 127.255.255.255 are reserved. Any addresses in this address block will be looped back into localhost. Any addresses in this address block will never appear on any network

4. Local example


 

 

Guess you like

Origin blog.csdn.net/liuqinhou/article/details/131749366