如何正确地ping一个解析为多个IP地址的主机名?

huangapple go评论76阅读模式
英文:

How to properly ping a hostname that resolves to multiple IP addresses?

问题

我想确保网络资源可用。

我知道如何ping一个单独的IP地址,大多数示例都展示了如何从主机名获取一个IP地址,然后对其进行ping。

但是由于主机名可以解析为多个IP地址,如IPAddress[] System.Networking.Dns.GetHostAddress(string)所返回的那样,我应该如何正确地处理这种情况?

我是否应该对它们都进行ping?如果其中任何一个可用,是否就足够了?

英文:

I want to ensure network resources are available.

I know how to ping a single IP address and most examples show how to get an IP from a hostname to then ping it.

But as a hostname can resolve to multiple IP addresses as returned by IPAddress[] System.Networking.Dns.GetHostAddress(string), how do I do that properly?

Should I ping all of them? Is it sufficient if any of them is available?

答案1

得分: 1

这取决于您想要验证什么。多个IP地址意味着服务可以从不同的物理服务器访问(可能位于世界上不同地区)。一个典型的应用程序会选择其中任何一个,从而导致服务器之间的隐式负载均衡。

因此,如果您想检查特定服务是否可访问,您可以随意ping其中任何一个地址。特别是如果这些是您自己的服务,您可能希望ping所有这些地址,以确保您的分布式服务器都正常工作。

无论哪种情况,您应该意识到ping是一种非常低级的检查服务可用性的方法。仅仅因为服务器响应ping请求并不代表其更高级别服务的可用性(例如http、电子邮件等)。甚至相反的情况也可能发生:服务器可能工作正常,但由于防火墙规则的原因而阻止ping请求。

英文:

That depends on what you want to verify. Multiple IPs means that the services are available from different physical servers (possibly in different parts of the world). A typical application would just take any of them, which then causes an implicit load balancing between the servers.

So if you want to check whether a particular service is reachable, you can just ping any of the addresses. Particularly if these are your own services you might want to ping all of them to make sure your distributed servers are all working.

In either case, you should be aware that pinging is a very low-level method of checking service availability. Just because a server responds to a ping request doesn't say anything about the availability of its higher-level services (e.g. http, e-mail, whatever). Even the opposite is true: The server might work just fine but have ping blocked by firewall rules.

huangapple
  • 本文由 发表于 2023年7月6日 15:27:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76626432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定