Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am running Windows 7 Home Premium 64-bit. Starting today, I noticed that DNS resolution is not reading my %SYSTEMROOT%\System32\drivers\etc\hosts file. I say this because I added two new entries to the file and when I run 'nslookup' on the command line, they don't resolve. Further, just trying to resolve 'localhost' results in my primary DNS server being queried.

I've read several threads that suggest that the file might have been corrupted and to move it aside and create a new one. I've done that, and no improvement.

Is there some sort of registry key that controls the sequence of resources used for DNS resolution (similar to nsswitch.conf on Unix)? What else could be causing this?

share|improve this question
    
I wonder, if you finally found a way to change this Windows 7 64-bit behavior, as I would require both methods (nslookup and ping) providing the same name resolution result! –  user94345 Aug 16 '11 at 10:11
add comment

3 Answers

up vote 6 down vote accepted

When you run an nslookup on an address, Windows will query the DNS server and won't look in the hosts file. Always. However, when it actually goes to connect, it will use the host files value. Try adding example.com to your hosts file, and have it point to 127.0.0.1. Run an nslookup: it will resolve to the actual IP address. Ping it. Your localhost will respond.

C:\>nslookup example.com
Server:  
Address:  10.110.5.1

Non-authoritative answer:
Name:    example.com
Address:  192.0.32.10


C:\>ping example.com

Pinging example.com [127.0.0.1] with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>
share|improve this answer
add comment

I have not managed to get my hosts file working on Windows 7 x64. The nasty thing is that with the exact same settings it works on x86.

So what I did, needing to block access to certain programs to certain sites was to use the free ZoneAlarm Personal Firewall. I know that this is the least elegant solution but for me there was no work around for this situation.

For me both ping and nslookup ignored the hosts file even though I have tried several versions and modifying to character encoding but with no success.

I don't know if anyone else could benefit from the solution I used, but just wanted to let you know that is exists and it works!

share|improve this answer
add comment

I struggled with this for too long, thinking that my antivirus software or something was the issue. In fact, my editor, Notepad, added the .txt extension to the file name, thus rendering it invisible for the system!

Check the extension. It should be empty! See also How can I reset the Hosts file back to the default?. This resets your host file back to original way it started out.

share|improve this answer
add comment

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.