主机名到ip是一对一的映射吗?

发布于 2024-11-28 16:46:07 字数 491 浏览 4 评论 0原文

主机名到ip是一对一的映射吗?一个主机名怎么能有多个IP地址呢? 根据 Java 的 getAllByName,它返回主机名的 ip 列表,但其文档似乎另有说明,或者至少没有解释一对多映射:

The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address.

http://download.oracle.com/javase/1.4.2/docs/api/java/net/InetAddress.html#getAllByName%28java.lang.String%29

is host name to ip a one-to-one mapping? how can a host name have multiple ip addresses?
according to Java's getAllByName, it returns a list of ips for a hostName, but its documentation seems to suggest otherwise or at least not explaining the one to many mapping:

The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address.

http://download.oracle.com/javase/1.4.2/docs/api/java/net/InetAddress.html#getAllByName%28java.lang.String%29

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

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

发布评论

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

评论(3

塔塔猫 2024-12-05 16:46:08

实际上,一台机器的 IP 取决于该机器所使用的网络接口卡 (NIC) 的数量。因此,如果一台机器安装了 3 个 NIC,则该机器将有 1 个主机名,但有 3 个不同的 IP。

Actually the IP's for a machine depends upon the number of Network Interface Cards(NIC) which are being used for that box. So if a machine has 3 NIC's installed, there will be 1 hostname for that box but 3 different IP's.

傻比既视感 2024-12-05 16:46:08

不,一个主机名可能有多个 A 记录,在这种情况下,解析器将以列表的形式返回所有 IP 地址。您几乎可以在每个大型网站上查看它:

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             283     IN      A       74.125.232.82
google.com.             283     IN      A       74.125.232.81
google.com.             283     IN      A       74.125.232.83
google.com.             283     IN      A       74.125.232.80
google.com.             283     IN      A       74.125.232.84

No, a hostname may have several A records and in this case resolvers will return all IP addresses as a list. You can check it on almost every large web site:

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             283     IN      A       74.125.232.82
google.com.             283     IN      A       74.125.232.81
google.com.             283     IN      A       74.125.232.83
google.com.             283     IN      A       74.125.232.80
google.com.             283     IN      A       74.125.232.84
停滞 2024-12-05 16:46:07

不可以,每个主机名可以有多个指向不同 IP 的 DNS A 记录。这通常用于高级负载平衡。您可以在 google.com 上进行检查:

$ host google.com
google.com has address 209.85.148.104
google.com has address 209.85.148.105
google.com has address 209.85.148.103
google.com has address 209.85.148.106
google.com has address 209.85.148.147
google.com has address 209.85.148.99
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.

No, every host name can have multiple DNS A records pointing to different IPs. This is often used for high-level load balancing. You can check that for example on google.com:

$ host google.com
google.com has address 209.85.148.104
google.com has address 209.85.148.105
google.com has address 209.85.148.103
google.com has address 209.85.148.106
google.com has address 209.85.148.147
google.com has address 209.85.148.99
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文