DNS and hosts file

thirdlegstump

Banned
Feb 12, 2001
8,713
0
0
Which takes priority when a browser or any application looks up a domain? Hosts file or the DNS servers? Say I make a route change for google.com to yahoo.com's IP address in the hosts, would the system still check the DNS even if the hosts file has a different entry?
 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
It looks at the hosts file first.

~\system\drivers\etc\hosts for Windows and /etc/hosts for *nix.

If it finds it in hosts, it doesn't go for a DNS request .... it thinks it already has a valid address.

FWIW

Scott
 

cleverhandle

Diamond Member
Dec 17, 2001
3,566
3
81
You know, it's easy to find out... :)

The hosts file will generally take priority, but it doesn't have to. Apps can be coded to do a DNS lookup directly, rather than use system name resolution. I know Sendmail does this sometimes, not sure about others...
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
On most unix systems you can control the priority with /etc/nsswitch.conf, I don't think you have any choice on Windows.
 

Cooky

Golden Member
Apr 2, 2002
1,408
0
76
Originally posted by: Nothinman
On most unix systems you can control the priority with /etc/nsswitch.conf, I don't think you have any choice on Windows.
Indeed, on Unix systems you get to list the order of priorities
example:
hosts: files nisplus nis dns

Microsoft hard coded certain DNS entries into Windows since sp2 and there's no way you can change them in hosts.
One example is msn.com.
I've tried to point msn.com to a bunch of different IPs in hosts file, and Windows still points to msn.com.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I can't imagine MS would do something stupid like hard code A records into their code, if they ever want to move the boxes hosting MSN.com they would have to release a patch to fix that. Most likely MS just went around the normal gethostbyname(3), etc calls and either asked the local DNS cache directly or did a direct DNS lookup themselves. Both are stupid, but there's not much you can do since it's closed source.
 

azev

Golden Member
Jan 27, 2001
1,003
0
76
If I wasnt mistaken, host file are loaded to memory when the computer start and yes it will look at records at host file first before using DNS.
I know there was a list of order of how MS windows resolve name, but i dont remember the whole thing.
 

Smilin

Diamond Member
Mar 4, 2002
7,357
0
0
It's not loaded when windows starts. The hostfile is checked each time you need to do a lookup.
 

Ichinisan

Lifer
Oct 9, 2002
28,298
1,235
136
Ctrl+F5 on yahoo.com?

Close all browser instances and reopen to make sure that it has not already cached old DNS queries in memory.