[Switch] difference between 127.0.0.1 and address 0.0.0.0

1. issues into

Before when using tomcat, start the tomcat default will be bound to this address 127.0.0.1, recently found the time to write a blog using hexo bind when to start the service by hexo server command ip address is 0.0.0.0. Then the two IP addresses in the end what difference will it make?

Before explaining two different addresses, let's review the basics of IP addresses.

2. IP address classification

2.1 IP address indicates

IP address consists of two parts, net-id and the host-id, i.e., the network number and host number. net-id: ip address represents the network number is located. host-id: ip numbers indicate a host network address is located in.

which is:

  IP-address ::=  { <Network-number>, <Host-number> }
复制代码

2.2 IP address classification

IP address is divided into a total of five categories, i.e., A ~ E, which are categorized by their net-id byte length occupied by several network number and a front.

  • Class A addresses: the network number (one byte). The first fixed network number is zero.
  • Class B addresses: the network number 2 bytes. The first two numbers of the fixed network 10.
  • Class C addresses: the network number 3 bytes. The first three bits 110 fixed network numbers.
  • Class D addresses: the first four bits is 1110, a multicast (multicast), i.e., one to many communications.
  • Class E Address: 1111 top four are reserved for future use. Wherein, the ABC three address is a unicast address (unicast), one for communication, is the most common.

2.3 Special IP addresses

Special IP address is used to do some special things. RFC1700 defines the following special IP address.

  1. {0,0}: the network number and host number are all 0, indicating "this host on this Network", only as the source address.
  2. {0, host-id}: a host on the local network. It can only be used as a source address.
  3. {-1, -1}: all the bits represent the network number and host number is 1 (binary), for broadcast on this network only as the destination address, the data packet sent to this address can not be forwarded to the the source address is located outside of the network.
  4. {Net-id, -1}: a direct broadcast to the specified network. It can only be used as a destination address.
  5. {Net-id, subnet-id, -1}: a direct broadcast to the specified sub-network to the network. Only as the destination address.
  6. {Net-id, -1, -1}: a direct broadcast to all subnetworks designated network. It can only be used as a destination address.
  7. {127}: the network number is any of 127 ip address. All internal host loopback address (loopback), can never appear outside of the host network.

3. Questions

Next, we asked the question before the point of view: the difference between 127.0.0.1 and 0.0.0.0 What is the address? Let's look at things in common:

  1. They belong to a special address.
  2. Class A addresses belong.
  3. All IPV4 addresses.

Next we look at these two addresses are:

0.0.0.0

In IPV4, address 0.0.0.0 is used to indicate an invalid, or unknown target unavailable.

  • In the server, 0.0.0.0 refers to all IPV4 addresses on the machine, if a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a service listening on the host address is 0.0.0.0, then by two ip address can access the service.

  • In the route, the default route 0.0.0.0 indicates that the routing table when no exact match is found when the route corresponding to the route.

Use summary

  • When a host has not been assigned an IP address when used to represent the host itself. (DHCP assigned IP address of the time)
  • As the default route, saying that "any IPV4 host." It represents the destination machine is unavailable.
  • As the server, it refers to any native IPV4 address.

127.0.0.1

127.0.0.1 belongs to {127} a set, and all the network address number 127 are called loopback addresses, loopback address! = 127.0.0.1, which is included relationship, that includes the loopback address 127.0.0.1. Loopback address: all packets sent to the address of the class should be loop back.

use

  • Loopback test by using the ping 127.0.0.1 network test equipment on a machine, operating system or TCP / IP implementation is working properly.
  • DDos attack prevention: After the site receives DDos attack, the domain A record to 127.0.0.1, that is, let the attacker's own attack their own.
  • Binding of time the majority of Web container testing local address.

localhost

Compared 127.0.0.1, localhost it has more significance. localhost is a domain name, rather than an ip address. The reason we often put 127.0.0.1 localhost and is considered to be the same because on most computers we use all speak 127.0.0.1 localhost point to this address. In ubuntu system, / ets / hosts file, there will be the following:

127.0.0.1   localhost
127.0.1.1   jason-Lenovo-V3000
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
复制代码

The first line will be above almost every computer and some default configuration. But the meaning is not limited to localhost 127.0.0.1.

localhost is a domain name, used to refer to this computer, or this host, it can be used to obtain network services running on the machine. In most systems, localhost is 127.0.0.1 points to the IPV4 and IPV6 is :: 1.

127.0.0.1    localhost
::1          localhost
复制代码

So, use the time to pay attention to confirm the IPV4 or IPV6

4. Summary

127.0.0.1 is a loopback address. It does not mean "native." 0.0.0.0 truly said that "this network the machine." In practical applications, generally we can choose to bind to 0.0.0.0 when the server port binding, so that my party can access the service access my services through my multiple ip addresses.

For example, I have a server, an Internet domain address A, a network address B, if I bind port is specified 0.0.0.0, so I can access applications through the network addresses or external addresses. But if I only bind the internal network address, you can not access the external network address. So if binding 0.0.0.0, there is a certain security risk, only for services that require network access, can bind only the network address.

 


Author: little sister the taste of
the link: https: //juejin.im/post/5d258b6ae51d454f73356dcf
Source: Nuggets
copyright reserved by the authors. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

The difference between 127.0.0.1 and 0.0.0.0 addresses

 

Guess you like

Origin www.cnblogs.com/mingjing/p/12535850.html
Recommended