localhost 和 0.0.0.0 的 IPV6 是什么? [英] What is IPV6 for localhost and 0.0.0.0?
问题描述
众所周知,localhost
的 IPv4 地址是 127.0.0.1
(环回地址).localhost
和 0.0.0.0
的 IPv6 地址是什么,因为我需要阻止一些广告主机.
As we all know the IPv4 address for localhost
is 127.0.0.1
(loopback address). What is the IPv6 address for localhost
and for 0.0.0.0
as I need to block some ad hosts.
推荐答案
众所周知,
localhost
的 IPv4 地址是127.0.0.1
(环回地址).
As we all know that IPv4 address for
localhost
is127.0.0.1
(loopback address).
实际上,127.0.0.0/8
中的任何 IPv4 地址都是环回地址.
Actually, any IPv4 address in 127.0.0.0/8
is a loopback address.
在 IPv6 中,环回范围的直接模拟是 ::1/128
.所以 ::1
(长格式 0:0:0:0:0:0:0:1
)是唯一的 IPv6 环回地址.
In IPv6, the direct analog of the loopback range is ::1/128
. So ::1
(long form 0:0:0:0:0:0:0:1
) is the one and only IPv6 loopback address.
虽然主机名 localhost
通常会解析为 127.0.0.1
或 ::1
,但我看到有人遇到过这样的情况将其绑定到不是环回地址的 IP 地址.这有点疯狂......但有时人们会这样做.
While the hostname localhost
will normally resolve to 127.0.0.1
or ::1
, I have seen cases where someone has bound it to an IP address that is not a loopback address. This is a bit crazy ... but sometimes people do it.
我说这太疯狂了",因为这样做可能会破坏应用程序的假设;例如应用程序可能会尝试对环回 IP 进行反向查找,但无法获得预期结果.在最坏的情况下,应用程序最终可能会意外地通过不安全的网络发送敏感流量……尽管您可能还需要犯其他错误才能实现"这一目标.
阻止 0.0.0.0
没有意义.在 IPv4 中,它永远不会被路由.IPv6 中的等价物是 ::
地址(长格式 0:0:0:0:0:0:0:0
)......它也从不路由.
Blocking 0.0.0.0
makes no sense. In IPv4 it is never routed. The equivalent in IPv6 is the ::
address (long form 0:0:0:0:0:0:0:0
) ... which is also never routed.
0.0.0.0
和 ::
地址保留表示任何地址".因此,例如,提供 Web 服务的程序可能绑定到 0.0.0.0
端口 80 以通过任何主机的 IPv4 地址接受 HTTP 连接.这些地址不能作为 IP 数据包的源地址或目标地址.
The 0.0.0.0
and ::
addresses are reserved to mean "any address". So, for example a program that is providing a web service may bind to 0.0.0.0
port 80 to accept HTTP connections via any of the host's IPv4 addresses. These addresses are not valid as a source or destination address for an IP packet.
最后,一些评论询问了 ::/128
与 ::/0
与 ::
.
Finally, some comments were asking about ::/128
versus ::/0
versus ::
.
这有什么区别?
严格来说,前两个是 CIDR 表示法,而不是 IPv6 地址.他们实际上是在指定一个范围的IP地址.CIDR 由一个 IP 地址和一个附加数字组成,该数字指定网络掩码中的位数.两者一起指定了地址范围;即通过忽略从给定地址中屏蔽的位形成的地址集.
Strictly speaking, the first two are CIDR notation not IPv6 addresses. They are actually specifying a range of IP addresses. A CIDR consists of a IP address and an additional number that specifies the number of bits in a netmask. The two together specify a range of addresses; i.e. the set of addresses formed by ignoring the bits masked out of the given address.
所以:
::
仅表示 IPv6 地址0:0:0:0:0:0:0:0
::/128
表示0:0:0:0:0:0:0:0
,网络掩码由 128 位组成.这给出了一个网络范围,其中只有一个地址.::/0
表示0:0:0:0:0:0:0:0
,网络掩码由 0 位组成.这给出了一个包含 2128 个地址的网络范围.即它是整个 IPv6 地址空间!
::
means just the IPv6 address0:0:0:0:0:0:0:0
::/128
means0:0:0:0:0:0:0:0
with a netmask consisting of 128 bits. This gives a network range with exactly one address in it.::/0
means0:0:0:0:0:0:0:0
with a netmask consisting of 0 bits. This gives a network range with 2128 addresses in it.; i.e. it is the entire IPv6 address space!
有关更多信息,请阅读有关 IPv4 和IPv6 地址和 CIDR 表示法:
For more information, read the Wikipedia pages on IPv4 & IPv6 addresses, and CIDR notation:
- https://en.wikipedia.org/wiki/IPv4_address
- https://en.wikipedia.org/wiki/IPv6_address
- https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
这篇关于localhost 和 0.0.0.0 的 IPV6 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!