127.0.0.1和0.0.0.0有什么区别?

127.0.0.1和0.0.0.0有什么区别?_第1张图片

Most of us have heard of ‘127.0.0.1 and 0.0.0.0’ but have probably not given much thought to them, but if both actually seem to point to the same location, then what is the actual difference between the two? Today’s SuperUser Q&A post helps clear things up for a confused reader.

我们大多数人都听说过“ 127.0.0.1和0.0.0.0”,但可能没有对它们进行太多思考,但是如果两者似乎都指向同一位置,那么两者之间的实际区别是什么? 今天的“超级用户”问答文章有助于为困惑的读者弄清一切。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

Photo courtesy of Kate Gardiner (Flickr).

图片由Kate Gardiner(Flickr)提供 。

问题 (The Question)

SuperUser reader Sagnik Sarkar wants to know what the difference between 127.0.0.1 and 0.0.0.0 is:

超级用户读者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也指向本地主机 (如果我错了,请纠正我)。 那么,127.0.0.1和0.0.0.0有什么区别?

What is the difference between 127.0.0.1 and 0.0.0.0?

127.0.0.1和0.0.0.0有什么区别?

答案 (The Answer)

SuperUser contributor DavidPostill has the answer for us:

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

What is the Difference Between 127.0.0.1 and 0.0.0.0?

127.0.0.1和0.0.0.0有什么区别?

  • 127.0.0.1 is the loopback address (also known as localhost).

    127.0.0.1是回送地址(也称为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).

    0.0.0.0是不可路由的元地址,用于指定无效,未知或不适用的目标(“无特定地址”占位符)。

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.

在服务器的上下文中,0.0.0.0表示本地计算机上的所有IPv4地址 。 如果主机有两个IP地址192.168.1.1和10.1.2.1,并且主机上运行的服务器侦听0.0.0.0,则在这两个IP上都可以访问它。

What is the IP Address 127.0.0.1?

什么是IP地址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.

127.0.0.1是回送Internet协议(IP)地址,也称为localhost 。 该地址用于建立与最终用户使用的同一台计算机或计算机的IP连接。

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 construct gives a computer or device capable of networking the capability to validate or establish the IP stack on the machine.

对于使用:: 1的含义支持IPv6寻址的计算机,定义了相同的约定。 最常见的做法是使用地址127.0.0.1建立连接。 但是,使用127…*范围内的任何IP地址都将以相同或相似的方式起作用。 环回结构使具有联网能力的计算机或设备能够验证或建立计算机上的IP堆栈。

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

来源: 127.0.0.1 –它的用途是什么,为什么重要?

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.

为A类网络号127分配了回送功能,即,由更高级别的协议发送到网络127地址的数据报应在主机内部回送。 发送到网络127地址的数据报永远不会出现在任何地方的任何网络上。

Source: Network Numbers

资料来源: 网络号码

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

如果是整个A类,则最后三个八位位组的其他任意值的意义是什么?

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.

回送范围的目的是测试主机上的TCP / IP协议实现。 由于较低的层是短路的,因此发送到环回地址可以有效地测试较高的层(IP和更高层),而不会在较低的层上出现问题。 127.0.0.1是最常用于测试目的的地址。

Source: IP Reserved, Loopback and Private Addresses

来源: IP保留,回送和专用地址

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

有关更多信息,请参见Ask Ubuntu问题: 什么是回送设备以及如何使用它?

What is the IP Address 0.0.0.0?

什么是IP地址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.

0.0.0.0是有效的地址语法。 因此,只要期望使用传统的点分十进制表示法的IP地址,它就应解析为有效。 一旦解析并转换为可行的数字形式,则其值确定接下来将发生什么。

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 connections, 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).

在路由条目的上下文中,它通常表示默认路由。 这是由于更多的地址掩码(选择要比较的位)导致的。 掩码0.0.0.0不会选择任何位,因此比较将始终成功。 因此,在配置了这样的路由后,总是会有地方可以发送数据包(如果配置了有效的目的地)。

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 ::).

在某些情况下,仅“ 0”也将起作用并具有相同的效果。 但这不能保证。 0.0.0.0格式是说“无特定地址”的标准方法(在IPv6中为:: 0::)

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

来源: IP地址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.

在Internet协议版本4中,地址0.0.0.0是不可路由的元地址,用于指定无效,未知或不适用的目标。 给原本无效的数据赋予特殊含义是带内信令的一种应用。

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).

在服务器的上下文中,0.0.0.0表示本地计算机上的所有IPv4地址 。 如果主机有两个IP地址192.168.1.1和10.1.2.1,并且主机上运行的服务器侦听0.0.0.0,则这两个IP都可以访问( 注意: 此特殊文本从上面重复了一部分总体答案 )。

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.

在路由上下文中,0.0.0.0通常表示默认路由,即通向Internet的“其余部分”而不是本地网络中某处的路由。

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.

    当主机尚未分配地址时,它声称该地址是其自身的地址。 例如在使用DHCP时发送初始DHCPDISCOVER数据包时。
  • 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 mechanism in modern operating systems.

    当通过DHCP的地址请求失败时,主机为自己分配的地址,只要主机的IP堆栈支持此地址。 在现代操作系统中,此用法已被APIPA机制取代。
  • A way to specify any IPv4-host at all. It is used in this way when specifying a default route.

    一种完全指定任何IPv4主机的方法 。 在指定默认路由时以这种方式使用它。

  • A way to explicitly specify that the target is unavailable. Source: 127.0.0.1 – What Are its Uses and Why is it Important?

    一种明确指定目标不可用的方法。 来源: 127.0.0.1 –它的用途是什么,为什么重要?

  • 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.]

    一种完全指定任何IPv4地址的方法 。 在配置服务器时(即,绑定侦听套接字时)以这种方式使用它。 TCP程序员将其称为INADDR_ANY。 [ bind(2)绑定到地址,而不是接口。 ]

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

在IPv6中,全零地址写为::

Source: 0.0.0.0 [Wikipedia]

资料来源: 0.0.0.0 [维基百科]

DHCP Discovery/Request

DHCP发现/请求

When a client boots up for the first time, it is said to be in the initializing state, and transmits 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.

客户端第一次启动时,它被称为处于初始化状态 ,并通过用户数据报协议(UDP)端口67(BootP服务器)在其本地物理子网上发送DHCPDISCOVER消息。 由于客户端无法知道其所属的子网,因此DHCPDISCOVER是广播的所有子网(目标IP地址为255.255.255.255),源IP地址为0.0.0.0。 由于客户端没有配置的IP地址,因此源IP地址为0.0.0.0。

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.

如果此本地子网上存在DHCP服务器,并且该DHCP服务器已配置并正常运行,则DHCP服务器将听到广播并以DHCPOFFER消息进行响应。 如果本地子网上不存在DHCP服务器,则此本地子网上必须有DHCP / BootP中继代理,才能将DHCPDISCOVER消息转发到包含DHCP服务器的子网。

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).

此中继代理可以是专用主机(例如,Microsoft Windows Server)或路由器(例如,配置有接口级IP帮助程序语句的Cisco路由器)。

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.

客户端收到DHCPOFFER之后,它将以DHCPREQUEST消息进行响应,指示其打算接受DHCPOFFER中的参数,并进入请求状态 。 客户端可能会收到多条DHCPOFFER消息,每个收到原始DHCPDISCOVER消息的DHCP服务器都会收到一条消息。 客户端选择一个DHCPOFFER并仅响应该DHCP服务器,从而隐式拒绝所有其他DHCPOFFER消息。 客户端通过使用DHCP服务器的IP地址填充“ 服务器标识符”选项字段来标识选定的服务器。

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 options that the client requires will be included in the options 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.

DHCPREQUEST也是广播,因此所有发送DHCPOFFER的DHCP服务器都将看到DHCPREQUEST,并且每个服务器都将知道其DHCPOFFER是被接受还是被拒绝。 客户端所需的任何其他配置选项将包含在DHCPREQUEST消息的选项字段中。 即使为客户端提供了IP地址,它也会发送带有源IP地址0.0.0.0的DHCPREQUEST消息。 目前,客户端尚未收到确认可以使用IP地址的验证。

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

客户端与客户端的服务器对话,获取客户端和DHCP服务器位于同一子网的DHCP地址:

127.0.0.1和0.0.0.0有什么区别?_第2张图片

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

来源: 了解和排除Catalyst Switch或企业网络中的DHCP故障

Default Route

默认路线

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

本文解释如何配置默认路由或最后的网关。 这些IP命令用于:

  • ip default-gateway

    ip default-gateway

  • ip default-network

    ip默认网络

  • ip route 0.0.0.0 0.0.0.0

    IP路由0.0.0.0 0.0.0.0

IP Route 0.0.0.0 0.0.0.0

IP路由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.

创建到网络0.0.0.0的静态路由0.0.0.0是在路由器上设置万不得已的网关的另一种方法。 与ip default-network命令一样,使用到0.0.0.0的静态路由不依赖于任何路由协议。 但是,必须在路由器上启用IP路由。

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.

注意: IGRP无法理解到0.0.0.0的路由。 因此,它不能传播使用ip route 0.0.0.0 0.0.0.0命令创建的默认路由。 使用ip default-network命令使IGRP传播默认路由。

Source: Configuring a Gateway of Last Resort Using IP Commands

资料来源: 使用IP命令配置不得已的网关



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程 。

翻译自: https://www.howtogeek.com/225487/what-is-the-difference-between-127.0.0.1-and-0.0.0.0/

你可能感兴趣的:(网络,java,linux,python,http)