开发者

is host name to ip a one-to-one mapping?

开发者 https://www.devze.com 2023-03-26 16:18 出处:网络
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 sugge

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


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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消