如何将域名解析为单个IP地址?

发布于 2024-10-21 16:38:00 字数 367 浏览 8 评论 0原文

我很惊讶地发现一个域名可以有多个 IP 地址。例如,以下是我的 Dns.GetHostAddresses("www.google.com") 结果:

{System.Net.IPAddress[6]}
    [0]: {74.125.127.147}
    [1]: {74.125.127.99}
    [2]: {74.125.127.103}
    [3]: {74.125.127.104}
    [4]: {74.125.127.105}
    [5]: {74.125.127.106}

(YMMV;地址似乎会定期更改)

这些不同的地址来自哪里,以及应该如何选择要连接的 IP 地址?

I was surprised to learn that a single domain name can have many IP addresses. For example, here are my results for Dns.GetHostAddresses("www.google.com"):

{System.Net.IPAddress[6]}
    [0]: {74.125.127.147}
    [1]: {74.125.127.99}
    [2]: {74.125.127.103}
    [3]: {74.125.127.104}
    [4]: {74.125.127.105}
    [5]: {74.125.127.106}

(YMMV; the addresses seem to change periodically)

Where do these different addresses come from, and how should one choose an IP address to connect to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜扑 2024-10-28 16:38:00

除非有特殊原因绑定到 IP,否则您应该在建立连接时使用 DNS 进行解析。

至于“它们从哪里来”,可以通过许多基础设施决策来回答。这就是 DNS 的强大之处,因为负载平衡、缓存、交付等系统可以从任意数量的源动态地提供域 (example.com),而您(客户端)不必担心该实现。

多个 DNS 可以是多个服务器、不同的数据中心、缓存网络等……具体取决于多种因素。

Unless there is a reason to specifically bind to the IP, you should use DNS to resolve at the moment you make the connection.

As for the "where do they come from", thats answered by any number of infrastructure decisions. This is the power of DNS, in that load balancing, caching, delivery, etc systems can dynamically serve up a domain (example.com) from any number of sources without you (the client) having to worry about that implementation.

The multiple DNS can be multiple servers, different datacenters, cache networks, etc ... depending on any number of factors.

北恋 2024-10-28 16:38:00

最有可能使用某种 RoundRobin。

您只能依赖域名,除非该域名在您的控制之下。

There are most likely using some sort of RoundRobin.

You can only rely on a domain name, unless the domain is under your control.

慕烟庭风 2024-10-28 16:38:00

IP 地址来自与查询的域名(示例中为 www.google.com)关联的 DNS 服务器。这与 Web 浏览器获取要连接的服务器 IP 地址的过程相同。

至于要连接到哪个 IP 地址,我想它们都是多余的,您可能应该只连接到第一个,但这只是猜测,我真的不确定。

The IP addresses come from the DNS server associated with the queried domain name, www.google.com in your example. This would be the same process a web browser follows to get the server IP addresses to connect to.

As for which IP address to connect to I'd imagine they're all redundant and you should probably just connect to the first one, however this is just speculation and I don't really know for sure.

聽兲甴掵 2024-10-28 16:38:00

您可以做几件事:

  1. 正确使用 System.Net.IPAddress[0]
    即刻。
  2. 您可以 ping 所有 6 个并且
    看看哪一个反应最好
    时间,缓存该值并尝试
    稍后使用它。

You can do a couple of things:

  1. Use System.Net.IPAddress[0] right
    off the bat.
  2. You can ping all 6 and
    see which one has the best response
    time, cache that value and try to
    use it later.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文