如何将域名解析为单个IP地址?
我很惊讶地发现一个域名可以有多个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除非有特殊原因绑定到 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.
最有可能使用某种 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.
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.
您可以做几件事:
即刻。
看看哪一个反应最好
时间,缓存该值并尝试
稍后使用它。
You can do a couple of things:
off the bat.
see which one has the best response
time, cache that value and try to
use it later.