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 have a local webserver running that I would like access as myserver.localhost, so I added an entry

127.0.0.1       myserver.localhost

to C:\Windows\System32\drivers\etc\hosts. This worked fine.

Then something happened. Among others, I had to disable Windows User Access Control, but I doubt that that is the cause. Now the system does not react to changes in the hosts file anymore. I commented out the entry, added new test entries, flushed the DNS cache several times, rebooted the machine, went for a break, nothing helps.

nslookup still returns 127.0.0.1 for myserver.localhost and non-existing domain for any test entries I add. To me it seems the file itself is broken in some way (it's just a text file, but anyway...) and Windows fails to work with it and therefore just returns whatever it thinks was the last good result.

Does anyone have an idea how to get back to a working hosts file without re-installing the entire system ?

share|improve this question

migrated from serverfault.com Aug 26 '10 at 9:28

This question came from our site for professional system and network administrators.

5 Answers 5

How did you edit the hosts file? Maybe the editor added an extension (.txt) to the file! Check from dos prompt (dir C:\Windows\System32\drivers\etc\hosts*).

share|improve this answer
1  
+1, good point. I've always hated that idea of hiding file extensions (by default, no less). Still remember those wacky .txt.exe... –  Massimo Aug 26 '10 at 8:17
    
one of the first things i do when setting up a Windows system is get rid of the crippling MS is forcing onto its users - display all files in the explorer (system files, etc.) and show the extensions. i did check in the dos 'shell', the file has the right name. thanks anyway. –  ssc Aug 29 '10 at 12:01

There is a general misunderstanding about how the HOSTS file in Windows and the nslookup tool interact. The value that you enter in the HOSTS file is what gets used by the system when you establish a connection to whatever domain name you might specify. This is essentially hard-coded by you entering it in the HOSTS file. However, nslookup ignores the HOSTS file for anything other than localhost. Try this: add an entry to your HOSTS file, and save the file. Do an nslookup: it should return the real IP address (or none if the real address doesn't exist). Now ping the host. It should ping the IP that you specified in the HOSTS file.

I don't know the exact reason for this behavior, but I believe it may be that nslookup always does a DNS query, and for anything at *.localhost, it asks the local machine what the address is (hence you get the result from the HOSTS file), but for anything else, it asks the DNS server which you have configured. This part is just speculation, but the actual behavior I described is something I've observed many times.

share|improve this answer
    
on that note, one weird thing i noticed is that the dns query response is reported to come from the dns server. pinging the host instead of nslookuping it might have help, but we've given up on Windows on the whole, see my own answer to the question. –  ssc Aug 29 '10 at 12:05

Changes to etc\hosts are picked up instantly. If that doesn't work, then you're either editing the wrong file (say you're working remote and accidentally picked the wrong server for the SMB mount) or a virus is interfering. Check that the virus scanner is up to date and check your whole system. Try a second virus scanner just to be safe.

share|improve this answer
    
Installing two active virus protection programs isn't usually a good idea... –  BloodPhilia Aug 26 '10 at 9:35
    
this is by far not the first time i work with the hosts file, i'm using it on an almost daily basis on Windows, Linux, Mac, etc., that's why the sudden failure puzzled me so much. first it worked, then it stopped working. it is the right file, though and there is no virus. –  ssc Aug 29 '10 at 12:07

You need to edit this file as administrator. Otherwise you can't change it.

Just press the start button - enter cmd in the search input box, right click on cmd and run it as administrator. Enter notepad and Open the file again, make your edits and save.

This is the way you need to use in Windows 7.

share|improve this answer
    
If he disabled UAC and he already has administrative rights with his user account, there's no need for this. –  Massimo Aug 26 '10 at 8:16
    
He has been able to change it already... –  BloodPhilia Aug 26 '10 at 9:34
up vote 0 down vote accepted

Unfortunately, there is no solution to this problem and no explainable reason for the cause. Something broke the file and the only way to fix it seems to be a complete re-installation of the entire system. We have abandoned on Windows as a development platform and moved to Mac and Linux.

share|improve this answer

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.