127.0.0.1和0.0.0.0之间有什么区别?

我们大多数人都听说过“127.0.0.1”和“0.0.0.0”,但可能没有考虑太多,但如果两者似乎都指向同一个位置,那么两者之间的实际区别是什么?今天的超级用户问答帖子帮助困惑的读者澄清了问题。...

127.0.0.1和0.0.0.0之间有什么区别?

我们大多数人都听说过“127.0.0.1”和“0.0.0.0”,但可能没有考虑太多,但如果两者似乎都指向同一个位置,那么两者之间的实际区别是什么?今天的超级用户问答帖子帮助困惑的读者澄清了问题。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

照片由凯特·加德纳(Flickr)提供。

问题

超级用户读者Sagnik Sarkar想知道127.0.0.1和0.0.0.0之间的区别是什么:

I understand that 127.0.0.1 points to localhost and that 0.0.0.0 also does as well (correct me if I am wrong). So, what is the difference between 127.0.0.1 and 0.0.0.0?

127.0.0.1和0.0.0.0之间有什么区别?

答案

超级用户贡献者DavidPostill为我们提供了答案:

What is the Difference Between 127.0.0.1 and 0.0.0.0?

  • 127.0.0.1 is the loopback address (also known as localhost).
  • 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown, or non-applicable target (a ‘no particular address’ place holder).

In the context of a route entry, it usually means the default route.

In the context of servers, 0.0.0.0 means all IPv4 addresses on the local machine. If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs.

What is the IP Address 127.0.0.1?

127.0.0.1 is the loopback Internet protocol (IP) address also referred to as the localhost. The address is used to establish an IP connection to the same machine or computer being used by the end-user.

The same convention is defined for computers that support IPv6 addressing using the connotation of ::1. Establishing a connection using the address 127.0.0.1 is the most common practice; however, using any IP address in the range of 127…* will function in the same or a similar manner. The loopback c***truct gives a computer or device capable of networking the capability to validate or establish the IP stack on the machine.

Source: 127.0.0.1 – What Are its Uses and Why is it Important?

Special Addresses

The class A network number 127 is assigned the loopback function, that is, a datagram sent by a higher level protocol to a network 127 address should loop back inside the host. No datagram sent to a network 127 address should ever appear on any network anywhere.

Source: Network Numbers

If it is Whole Class A, What is the Point of Other Arbitrary Values for the Last Three Octets?

The purpose of the loopback range is testing of the TCP/IP protocol implementation on a host. Since the lower layers are short-circuited, sending to a loopback address allows the higher layers (IP and above) to be effectively tested without the chance of problems at the lower layers manifesting themselves. 127.0.0.1 is the address most commonly used for testing purposes.

Source: IP Reserved, Loopback and Private Addresses

For more information see the Ask Ubuntu question: What is the Loopback Device and How do I Use it?

What is the IP Address 0.0.0.0?

0.0.0.0 is a valid address syntax. So it should parse as valid wherever an IP address in traditional dotted-decimal notation is expected. Once parsed and converted to workable numeric form, then its value determines what happens next.

The all-zero value does have a special meaning. So it is valid, but has a meaning that may not be appropriate (and thus treated as not valid) for particular circumstances. It is basically the ‘no particular address’ placeholder. For things like address binding of network connecti***, the result can be to assign an appropriate interface address to the connection. If you are using it to configure an interface, it can instead remove an address from the interface. It depends on the context of use to determine what ‘no particular address’ really does.

In the context of a route entry, it usually means the default route. That happens as a result more of the address mask, which selects the bits to compare. A mask of 0.0.0.0 selects no bits, so the comparison will always succeed. So when such a route is configured, there is always somewhere for packets to go (if configured with a valid destination).

In some cases, merely ‘0’ will also work and have the same effect. But this is not guaranteed. The 0.0.0.0 form is the standard way to say ‘no particular address’ (in IPv6 that is ::0 or just ::).

Source: What is the Meaning of the IP Address 0.0.0.0?

In Internet Protocol version 4, the address 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown, or non applicable target. To give a special meaning to an otherwise invalid piece of data is an application of in-band signaling.

In the context of servers, 0.0.0.0 means all IPv4 addresses on the local machine. If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs (Note: This particular text is repeated from above as part of the overall answer).

In the context of routing, 0.0.0.0 usually means the default route, i.e. the route which leads to ‘the rest of’ the Internet instead of somewhere on the local network.

Uses Include:

  • The address a host claims as its own when it has not yet been assigned an address. Such as when sending the initial DHCPDISCOVER packet when using DHCP.
  • The address a host assigns to itself when an address request via DHCP has failed, provided the host’s IP stack supports this. This usage has been replaced with the APIPA mechani** in modern operating systems.
  • A way to specify any IPv4-host at all. It is used in this way when specifying a default route.
  • A way to explicitly specify that the target is unavailable. Source: 127.0.0.1 – What Are its Uses and Why is it Important?
  • A way to specify any IPv4 address at all. It is used in this way when configuring servers (i.e. when binding listening sockets). This is known to TCP programmers as INADDR_ANY. [bind(2) binds to addresses, not interfaces.]

In IPv6, the all-zeros-address is written as ::

Source: 0.0.0.0 [Wikipedia]

DHCP Discovery/Request

When a client boots up for the first time, it is said to be in the initializing state, and tran**its a DHCPDISCOVER message on its local physical subnet over User Datagram Protocol (UDP) port 67 (BootP server). Since the client has no way of knowing the subnet to which it belongs, the DHCPDISCOVER is an all subnets broadcast (destination IP address of 255.255.255.255), with a source IP address of 0.0.0.0. The source IP address is 0.0.0.0 since the client does not have a configured IP address.

If a DHCP server exists on this local subnet and is configured and operating correctly, the DHCP server will hear the broadcast and respond with a DHCPOFFER message. If a DHCP server does not exist on the local subnet, there must be a DHCP/BootP Relay Agent on this local subnet to forward the DHCPDISCOVER message to a subnet that contains a DHCP server.

This relay agent can either be a dedicated host (Microsoft Windows Server, for example) or a router (a Cisco router configured with interface level IP helper statements, for example).

After the client receives a DHCPOFFER, it responds with a DHCPREQUEST message, indicating its intent to accept the parameters in the DHCPOFFER, and moves into the requesting state. The client may receive multiple DHCPOFFER messages, one from each DHCP server that received the original DHCPDISCOVER message. The client chooses one DHCPOFFER and responds to that DHCP server only, implicitly declining all other DHCPOFFER messages. The client identifies the selected server by populating the Server Identifier option field with the DHCP server’s IP address.

The DHCPREQUEST is also a broadcast, so all DHCP servers that sent a DHCPOFFER will see the DHCPREQUEST, and each will know whether its DHCPOFFER was accepted or declined. Any additional configuration opti*** that the client requires will be included in the opti*** field of the DHCPREQUEST message. Even though the client has been offered an IP address, it will send the DHCPREQUEST message with a source IP address of 0.0.0.0. At this time, the client has not yet received verification that it is clear to use the IP address.

Client-server conversation for a client obtaining a DHCP address where the client and DHCP server reside on same subnet:

007Ys3FFgy1gpeb535hm0j30hd042q3b

Source: Understanding and Troubleshooting DHCP in Catalyst Switch or Enterprise Networks

Default Route

This document explains how to configure a default route or gateway of last resort. These IP commands are used:

  • ip default-gateway
  • ip default-network
  • ip route 0.0.0.0 0.0.0.0

IP Route 0.0.0.0 0.0.0.0

Creating a static route to the network 0.0.0.0 0.0.0.0 is another way to set the gateway of last resort on a router. As with the ip default-network command, using the static route to 0.0.0.0 is not dependent on any routing protocols. However, IP routing must be enabled on the router.

Note: IGRP does not understand a route to 0.0.0.0. Therefore, it cannot propagate default routes created using the ip route 0.0.0.0 0.0.0.0 command. Use the ip default-network command to have IGRP propagate a default route.

Source: Configuring a Gateway of Last Resort Using IP Commands


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-10 07:44
  • 阅读 ( 313 )
  • 分类:互联网

你可能感兴趣的文章

二项式(binomial)和正态分布(normal distribution)的区别

...中,二项分布和正态分布是现实生活中最常见的两种。 什么是二项分布? 二项式分布是与随机变量X相对应的概率分布,它是一系列独立的是/否实验的成功次数,每个实验都有一个成功的概率p。从X的定义来看,它显然是一个离...

  • 发布于 2020-10-24 22:11
  • 阅读 ( 1995 )

如何将ip地址追踪到pc&如何找到自己的ip地址

... 什么是ip地址(an ip address)? ...

  • 发布于 2021-03-15 16:53
  • 阅读 ( 467 )

如何让python和javascript使用json进行通信

有没有想过如何在两种编程语言之间发送数据?是否尝试发送一个对象或多个数据段? ...

  • 发布于 2021-03-16 01:22
  • 阅读 ( 302 )

以低于5美元的价格制作一个pov-led空中写手

...把每个焊脚焊接到它们各自的焊盘上,然后把铁放在它们之间加热两个接头,最后再添加更多的焊料来填补它们之间的间隙。 ...

  • 发布于 2021-03-16 12:02
  • 阅读 ( 168 )

升级您的圣诞花环与运动激活led矩阵

... 刷新速度变量。此变量确定每次屏幕刷新之间的时间间隔。数字越大,等待的时间就越长。 ...

  • 发布于 2021-03-16 16:22
  • 阅读 ( 208 )

redis和php快速数据存储入门

... 127.0.0.1:6379> ...

  • 发布于 2021-03-28 11:57
  • 阅读 ( 318 )

ip地址是如何工作的?

...个数字都是255或0。从255到0的位置变化表示网络和主机ID之间的划分。255s从等式中“掩盖”了网络ID。 注意:我们在这里描述的基本子网掩码称为默认子网掩码。在更大的网络上,事情会变得更复杂。人们经常使用自定义子网掩...

  • 发布于 2021-04-06 18:43
  • 阅读 ( 192 )

如何在windows、mac或linux上编辑主机文件

... 微软在Windows网络中保持了hosts文件的活跃性,这就是为什么它在Windows、macOS或Linux中的使用差别很小的原因。所有平台的语法基本相同。大多数主机文件都会有多个环回条目。我们可以用它作为典型语法的基本示例。 第一部分...

  • 发布于 2021-04-08 01:34
  • 阅读 ( 168 )

127.0.0.1和0.0.0.0之间有什么区别?

...考虑太多,但如果两者似乎都指向同一个位置,那么两者之间的实际区别是什么?今天的超级用户问答帖子帮助困惑的读者澄清了问题。 今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的...

  • 发布于 2021-04-10 07:44
  • 阅读 ( 313 )

127.0.0.0和127.0.0.1有什么区别?

... On-link 127.0.0.1 306 我们能从这张桌子上挑出什么样的信息? 答案 两个超级用户贡献者加入进来帮助解开这个谜团。首先,Mmmc提供了以下简明概述: No. You cannot use them both. And they are not both loopback adresses. 127.0.0.1 is a...

  • 发布于 2021-04-11 21:41
  • 阅读 ( 179 )
899664824
899664824

0 篇文章

相关推荐