15

I'm having a DNS resolving issue that is affecting the performance of my locally hosted web site when browse it on my local machine. If I attach my network's DNS suffix to my local machine name when I go to the URL in my browser, the site has terrible load times (100+ times slower) than without the DNS suffix.

I thought I could fix this by using my hosts file to avoid the need for a lookup. I added an entry to my hosts file like this

127.0.0.1    myMachine.MyDnsSuffix

But this didn't change the load times, even after a reboot. Although it is not important to resolve this specific problem, I would really like to know why this happens.

Also, when I run nslookup on the domain myMachine.MyDnsSuffix, I notice it uses my network's DNS server to find the IP. Could this be related to my problem or am I just mis-understanding how nslookup works?

Dan Herbert
  • 253
  • 1
  • 3
  • 6

7 Answers7

23

I believe nslookup is used to test a DNS server itself, as opposed to utilizing your HOSTS file. http://support.microsoft.com/kb/200525 seems to indicate as much.

Try just a simple ping. Does ping myMachine.MyDnsSuffix resolve to the loopback address you have specified in your HOSTS file?

Christopher Karel
  • 6,442
  • 1
  • 26
  • 34
  • You made a good point about `nslookup`. I just tried pinging the `myMachine.MyDnsSuffix` and it resolved to my IP on the network, not `127.0.0.1` like specified in my HOSTS file. – Dan Herbert Dec 16 '09 at 17:48
  • What's your OS? I think Windows7 and possibly Vista has some weird UAC protections on the HOSTS file. Are you certain your changes are saving properly? – Christopher Karel Dec 16 '09 at 17:54
  • My OS is Windows XP. The changes seem to be getting saved properly. – Dan Herbert Dec 16 '09 at 17:57
  • Hmm...there isn't a hash mark at the start of that HOSTS entry, is there? (that would make it a comment) And you're sure it's in C:\Windows\System32\drivers\etc\hosts? Can you add a dummy entry there, and see if that resolves as you specify? – Christopher Karel Dec 16 '09 at 18:25
  • 4
    Oh, and don't forget to clear your name cache. `ipconfig /flushdns`. And the NETBIOS cache too: `nbtstat -R`. (Case sensitive in windows -- WTF, why?!?) – Christopher Karel Dec 16 '09 at 18:28
  • I just tried adding a dummy entry into my HOSTS file and it picked it up immediately. – Dan Herbert Dec 16 '09 at 18:34
  • The dummy entry is likely not in the cache. I wager that flushing the caches as christopher suggests will get the hosts file entry used. – tomjedrz Dec 16 '09 at 19:47
  • Sending a ping is not a valid method, as that will initiate a connection with the remote server, which might not be something that you want to do if you're just looking up the DNS. Not to mention the wasted bandwidth. – Darth Egregious Nov 18 '14 at 17:33
8

DNS lookups do not use a hosts file. Ever.

user9517
  • 114,104
  • 20
  • 206
  • 289
adaptr
  • 16,479
  • 21
  • 33
  • 3
    @BartDeVos no, it's not wrong. A generic _host_ lookup (i.e. `gethostbyname()` can go via the hosts file, or via DNS, but a _DNS-specific_ lookup (as performed by `nslookup`) will not use the hosts file. – Alnitak Dec 21 '11 at 14:48
  • That said, gethostinfo/getaddrinfo (the modern versions of gethostbyname) are POSIX, and not necessarily what Windows uses. – adaptr Dec 21 '11 at 15:18
2

OK, brand new approach. Let's have you clear your IP and NETBIOS cache. ipconfig /flushdns and nbtstat -R. Then fire up a packet sniffer like Wireshark, and do a ping while it's running.

From the packet capture, we want to see if A) There's a DNS request going out, and if so, what name is it requesting. B) If there's a NETBIOS request going out. It's possible this name is being resolved via NETBIOS instead of proper DNS.

If we don't see either of the above despite you flushing your cache, then it's likely that the name is being pulled from either hosts or lmhosts.

Christopher Karel
  • 6,442
  • 1
  • 26
  • 34
1

Some people on web forums claim that creating a new hosts file and restarting the DNS client service fixes the problem, but I'm not sure why that would work if you've already tried rebooting.

I realize this is a longshot, but there aren't any Microsoft-related words like MSDN, Microsoft, or MSN in the hosts file entry, are there? Microsoft has written dnsapi.dll to ignore hosts file entries matching certain names. For example, if I add the following entry, Windows skips it and resolves both hostnames in the entry using DNS:

127.0.0.1 www.microsoft.com www.mysite.com
jlupolt
  • 884
  • 1
  • 7
  • 10
  • I don't have any microsoft related stuff in my HOSTS file. I only have a few internal test domains assigned. My HOSTS file is pretty basic. – Dan Herbert Dec 17 '09 at 16:37
  • Hmm, interesting. I knew that they hard-coded MS domains to ignore the `HOSTS` file, but even the non-MS domain gets ignored if it shares an entry with an MS domain? That’s just poor programming on their part. This is definitely something to look out for if “minifying” a `HOSTS` file. – Synetech Aug 31 '13 at 17:58
0

http://geekswithblogs.net/JanS/archive/2009/06/17/beware-of-spacing-in-windows7-hosts-file.aspx

This appears to be the actual cause. Leave it to Microsoft to suddenly and without warning ignore a 25 year old convention.

  • 4
    Please include a gist of the answer/cause in your answer. It is much nicer than just a link. – Jacob Nov 05 '12 at 05:24
  • 1
    Here is the essential part of the linked URL **However, nothing seemed to work. Until I saw some other example hosts files that were formatted as ** – Tun Aug 24 '17 at 05:37
  • Archived copy of now-dead link for context: https://web.archive.org/web/20200221091750/http://geekswithblogs.net/JanS/archive/2009/06/17/beware-of-spacing-in-windows7-hosts-file.aspx – sparrowt Oct 07 '21 at 09:19
0

When using the full DNS name your browser is attempting to go through your proxy server - clicky for IE.

The hosts file or name resolution order is nothing to do with this problem, and the festering sore on the backside of humanity that is the hosts file should be taken out back and noisily shot.

Maximus Minimus
  • 8,937
  • 1
  • 22
  • 36
-1

http://www.tweaksforgeeks.com/windows7/2011/02/windows-7-hosts-file-ignored <-- Work for me!

Babblo
  • 7
  • 1
  • 10
    Welcome to Server Fault! Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Ben Pilbrow Mar 27 '11 at 16:37