Windows 7 stopped using the 'hosts' file for DNS resolution

6

2

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?

AJ.

Posted 2010-04-14T00:18:24.643

Reputation: 3 491

1I 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! – None – 2011-08-16T10:11:14.973

Answers

11

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:\>

nhinkle

Posted 2010-04-14T00:18:24.643

Reputation: 35 057

Your example doesn't work on Windows 7 x64. ping says could not find host – Carlos Rendon – 2015-05-21T21:41:12.430

0

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!

Jano Rajmond

Posted 2010-04-14T00:18:24.643

Reputation: 21

0

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.

Mark

Posted 2010-04-14T00:18:24.643

Reputation: 1

-1

I had the same problem and this worked for me in Win 7.

When you add your new entries to the hosts file, make sure you use all spaces, no tabs.

That got it working for me.

Paul T

Posted 2010-04-14T00:18:24.643

Reputation: 1