Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
669 views
in Technique[技术] by (71.8m points)

c# - Dns.GetHostEntry returns multiple IP addresses

This question probably highlights a lack of understanding of networking principals on my part, rather than a programming issue.

I'm doing a lookup on a hostname using

Dns.GetHostEntry

This returns an IPHostEntry to me, which has an AddressList property which is an array of IPAddress.

I always thought there is a 1 to 1 mapping between hostname and IP, but I'm finding that in some cases I get back several IPAddress(es) for the same host.

This is a surprise to me.

Which part of domain name resolution do I not understand?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The mappings between physical network interfaces, DNS names and IP addresses is practically arbitrary. However you should distinguish between network interfaces (typically Ethernet adapters, Wifi adapters, Bluetooth network devices etc.) and the DNS side of things, which only deals with names and IP addresses (not physical interfaces).

Here are some facts that you can mix and match:

  • a single network card can have 1 or many IP addresses.
  • a single DNS name can be resolved to 1 or many IP addresses.
  • a single IP address can (and will usually) identify a single machine
  • mulitple DNS names can be mapped to a single IP address

Consider hosting providers: They will have many DNS names pointing to the same - shared - server. That server might for reasons of reliablilty be equipped with multiple network cards, each with several IP addresses.

For PCs you will usually get more than one IP address if you query by hostname, because nowadays you typically have at least two (wifi and ethernet) adapters with their individual (mostly single) IP address. In load-balancing scenarios however all sorts of clever mappings and redirections (virtual IP addresses and the like) can occur.

Both DNS and IP protocols are very flexible, however this of course does not necessarily make them easier to understand.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...