Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that you shouldn't have duplicate entries in your Windows NT hosts file, windows\system32\drivers\etc\hosts, but what is the expected behavior if you have them?

You can have multiple entries with the same hostname but different addresses in the Windows NT hosts file (windows\system32\drivers\etc\hosts). When you access that host on the network, the Windows DNS system will resolve it to one of those entries. How can I tell which entry will be used?


Edit: This particular example seems to force special behavior. The loopback seems to override any entry, regardless of order.


I am seeing the first entry in the list take precedence.

But, is the behavior I am seeing guaranteed, is it version specific, or is it generally unreliable?

The reason I ask is because I am writing some scripts to handle hosts, and I am trying to figure out if I can reliably select one of them to remove/comment out, and expect there to be no impact to the user's system.

share|improve this question
Just noticed that seems to force special behavior. I edited the question to ask about the different scenarios... – Merlyn Morgan-Graham Jul 19 '11 at 8:02
Who says that one cannot have multiple entries with the same domain name and different IP addresses? Certainly not Microsoft. It's a perfectly legitimate thing, according to Microsoft. – JdeBP Jul 19 '11 at 11:45
@JdeBP: I know this is bordering on a second question, but if a host is multi-homed, what does that mean, and how is that useful to me? If I ping it, I'll only get one address. Same if I try to terminal-serve to it. BTW, your link is quite useful to me, as it backs up the behavior I described in my question. You should write an answer :) – Merlyn Morgan-Graham Jul 19 '11 at 16:58
Tried to edit the question to make it less inaccurate, based on JdeBP's comment. – Merlyn Morgan-Graham Mar 13 '12 at 4:47

Only the first will be read. Once the name has been resolved, no further reading of the file takes place.

share|improve this answer
One: You contradict the question. Two: The hosts file is read in its entirety when the DNS Client service is enabled, and multiple entries with the same domain name are quite legitimate. – JdeBP Jul 19 '11 at 11:44
@Synetech: Can you clarify which part is incorrect? Is it the part JdeBP already mentioned on the OP (that you can have multiple entries with the same domain) or is there something else I've missed? :) – Merlyn Morgan-Graham Mar 13 '12 at 4:40

I have tried 5 minutes ago and it runs without dns server on the following way into the windows hosts file:

ip1,ip2,ipx name_to_resolve

Sorry my english...

share|improve this answer
could u explain in brief how it answers the question – BlueBerry - Vignesh4303 Oct 8 '15 at 9:02
up vote 0 down vote accepted

Multiple entries with the same domain name is allowed and useful in some scenarios.

As I described in my question, it seems that in "normal" cases, where those addresses are reachable by the same adapter, the first address seems to be the one that is taken. If one of those entries is loopback (, it might take precedence though.

Sometimes it makes sense to have multiple entries with the same domain name, even when none of the addresses are to the loopback adapter, if the computer is multihomed or multiaddressable. (Thanks JdeBP for the info in the comments on my OP).

a single DNS host name can correspond to more than one IP address if each of the addresses is mapped and used in separate lines. For example, you can add lines for the following multihomed or multiaddressable DNS host computer:

I believe that adapter preference/priority might play a role here (which you can set up in network settings), though I cannot test it out. Loopback will most likely always come first in adapter preference.

share|improve this answer
I can't test out adapter preference/priority at this point, so please comment if you know this to be correct or incorrect. – Merlyn Morgan-Graham Dec 7 '11 at 22:41

> The loopback seems to override any entry, regardless of order.

Did you make sure to close and re-run the client (browser?) after making the change? If you don’t, then it will likely still be using the old values and not see the change in order until it is restarted. Further, if you have the DNS Client service running, the old values are cached, so you will not see the change.

I did some tests and it seems that the first entry is always the one that is used.

Make sure to restart the client to ensure that it is re-reading the HOSTS file, and if you have the DNS Client service running also run ipconfig /flushdns

share|improve this answer
Can't remember if I did or not, as I was working with this between 3 to 8 months ago. But good point and thanks for checking into this. Do you have multiple adapters, and can you check if the adapter preference settings I mentioned in my self-answer have any impact? – Merlyn Morgan-Graham Mar 13 '12 at 4:38
Actually, multiple NIC order was discussed recently. – Synetech Mar 13 '12 at 4:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .