Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I ran into the following problem under Windows 7: name resolution uses the result from a DNS lookup instead of using what I have in my local hosts file. This is different from previous versions of Windows. What workarounds are there to fix this bug?

Example:

My local hosts file contains the following entries (I disabled IPv6):

#       ::1             localhost
127.0.0.1               localhost
127.0.0.1               svn.mydomain

I can ping svn.mydomain and Windows 7 resolves the name as 127.0.0.1, as expected.

However, nslookup resolves svn.mydomain as 192.168.4.105, which is the entry that comes from my office network's domain nameserver. Windows XP correctly returns 127.0.0.1. I recently moved the server in-house, which is why the svn.mydomain resolves through DNS now, but doesn't when I am outside the office network. I would prefer to not remove that host from DNS.

I specifically put this entry in hosts so I could create a secure tunnel to the Subversion repository on my server (localhost -> svn.mydomain) regardless of my network connection, and it is configured to respond only through a tunneled connection. This bug broke that solution and I'd really like to "resolve" (yes, pun intended) this problem.

How do I keep Windows 7 name resolution from overriding hosts entries?

share|improve this question
    
Somebody over at StackOverflow directed me to this site as a better place to get my question answered. –  Suncat2000 Mar 15 '11 at 20:47

2 Answers 2

up vote 5 down vote accepted

nslookup will return what the name servers actually return (as the name implies), but that's not the whole picture of name resolution. The hosts file takes priority, and netbios can be used, too.

As you've said, ping is working correctly, as should other applications that use the OS's name resolution functionality. nslookup's ignoring of the hosts file is inconsequential.

share|improve this answer
    
Thanks for the comment. I know that the hosts file should take priority, but that is not what Windows 7 is really doing. I'm trying to find out how to force it to take priority, as it did in previous versions of Windows. –  Suncat2000 Mar 15 '11 at 20:57
1  
@Suncat2000 it already is priority; your ping command is evidence of this. nslookup ignores the hosts file, because that's how it works. But, SVN, web browsers, and everything else you might be needing this for, are already obeying your hosts file. –  Shane Madden Mar 15 '11 at 20:59
1  
I assumed the identical behavior of my Subversion client and nslookup were due to the same reason. I'm embarrassed to say that was a bad assumption on my part. It was a faulty tunnel configuration that was making the Subversion connection fail. I was unaware that nslookup did not use all name resolution paths. Thanks for that fact. –  Suncat2000 Mar 15 '11 at 21:29

NSLOOKUP is not going to look at your HOSTS file... you are directly querying your DNS server. Hence, it will return your DNS server's record regardless of your local HOSTS file.

share|improve this answer
    
OK, thanks. But nslookup is behaving the same as my Subversion client, and anybody who would have an answer to my question has access to nslookup. The crux of the matter is that Windows 7's name resolution is somehow broken and I need a way to fix it. –  Suncat2000 Mar 15 '11 at 21:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.