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

use*_*480 5 ip hostname

ip是一对一映射的主机名吗?主机名如何有多个IP地址?根据Java的getAllByName,它返回一个hostName的ips列表,但是它的文档似乎暗示或者至少没有解释一对多的映射:

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

Luk*_*ský 8

不,每个主机名都可以有多个指向不同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.
Run Code Online (Sandbox Code Playgroud)