Dns.GetHostEntry 返回多个 IP 地址
这个问题可能凸显了我对网络原理缺乏理解,而不是编程问题。
我正在使用 This 返回一个 IPHostEntry 来查找主机名
Dns.GetHostEntry
,它有一个 AddressList 属性,它是一个 IPAddress 数组。
我一直认为主机名和 IP 之间存在 1 对 1 的映射,但我发现在某些情况下我会返回同一主机的多个 IP 地址。
这对我来说是一个惊喜。
我不明白域名解析的哪一部分?
This question probably highlights a lack of understanding of networking principals on my part, rather than a programming issue.
I'm doing a lookup on a hostname using
Dns.GetHostEntry
This returns an IPHostEntry to me, which has an AddressList property which is an array of IPAddress.
I always thought there is a 1 to 1 mapping between hostname and IP, but I'm finding that in some cases I get back several IPAddress(es) for the same host.
This is a surprise to me.
Which part of domain name resolution do I not understand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
物理网络接口、DNS 名称和 IP 地址之间的映射实际上是任意的。 然而,您应该区分网络接口(通常是以太网适配器、Wifi 适配器、蓝牙网络设备等)和 DNS 方面,后者仅处理名称和 IP 地址(而不是物理接口)。
以下是您可以混合搭配的一些事实:
考虑托管提供商:他们将有许多指向同一共享服务器的 DNS 名称。 出于可靠性原因,该服务器可能配备多个网卡,每个网卡都有多个 IP 地址。
对于 PC,如果按主机名查询,通常会获得多个 IP 地址,因为现在您通常至少有两个(wifi 和以太网)适配器及其各自的(大多数是单个)IP 地址。
然而,在负载平衡场景中,可能会发生各种巧妙的映射和重定向(虚拟 IP 地址等)。
DNS 和 IP 协议都非常灵活,但这并不一定会使它们更容易理解。
The mappings between physical network interfaces, DNS names and IP addresses is practically arbitrary. However you should distinguish between network interfaces (typically Ethernet adapters, Wifi adapters, Bluetooth network devices etc.) and the DNS side of things, which only deals with names and IP addresses (not physical interfaces).
Here are some facts that you can mix and match:
Consider hosting providers: They will have many DNS names pointing to the same - shared - server. That server might for reasons of reliablilty be equipped with multiple network cards, each with several IP addresses.
For PCs you will usually get more than one IP address if you query by hostname, because nowadays you typically have at least two (wifi and ethernet) adapters with their individual (mostly single) IP address.
In load-balancing scenarios however all sorts of clever mappings and redirections (virtual IP addresses and the like) can occur.
Both DNS and IP protocols are very flexible, however this of course does not necessarily make them easier to understand.
任何系统都可以有多个网络接口和互联网地址,但只有一个名称。 从名称到地址的正向映射将返回映射到特定名称的所有地址。 我们过去对文件服务器执行此操作,以便主机在访问文件时不必遍历网络边界并将负载分散到各个 NIC。 文件服务器将驻留在每个不同的子网上,具有多个接口卡,每个接口卡具有不同的子网地址,但名称相同。 校园内的DNS服务器仍然是这样设置的。 此外,您可能有一个映射到多个系统的名称,通过 DNS 提供某种级别的负载平衡。
Any system can have multiple network interfaces and internet addresses, yet only have one name. The forward mapping from name to address will return all of the addresses mapped to a particular name. We used to do this with our file servers so that hosts wouldn't have to traverse a network boundary when accessing files and to spread the load out across the various NICs. The file servers would be homed on each of our various subnets, having multiple interface cards, each with a different subnet address, but the same name. The DNS servers on campus are still set up this way. Additionally, you may have a name that maps to more than one system, providing some level of load balancing via DNS.
一种可能性:
一个名称可以解析为多个地址,这有时用于循环
这是平衡服务器负载的一种较弱的方式。
One possibility:
A name can resolve to more than one address, this is sometimes used for round robin
it's a weak way of load balancing your servers.
您可以拥有来自多个网络适配器或多个协议的多个地址。
通常您会拥有同一主机的 IPV4 和 IPV6 地址。
You can have multiple adresses from multiple network adapters or multiple protocols.
Often you'll have IPV4 and IPV6 adress for the same host.
据我所知,可以允许一个主机名有多个 IP 地址以实现高可用性。 即:当一台机器宕机时,将使用另一台机器。
As far as I know it is possible to allow multiple IP addresses for one hostname to allow for high-availability. That is: when one machine is down, another one will be used.