Windows 7 – Edit the Hosts File

Need to figure out how to edit the Hosts file in Windows 7? For the most part, it’s pretty much the same as Windows XP and Vista, but with a few extra hiccups!

Just if case you don’t know, the Hosts file is where you can manually enter a hostname and an IP address pair, thereby bypassing the DNS server. This can be pretty useful in certain situation, especially for anyone in IT.

The path to the Hosts file in Windows 7 is the same as usual:

%systemroot%\system32\drivers\etc\

where %systemroot% is usually c:\windows unless you installed Windows on a different partition. By default, you cannot see these hidden folders since they are system folders.

To show hidden folders in Windows 7, press the ALT key while in Explorer to bring up the File menu. Click on Tools and then Folder Options.

hosts file windows 7

Click on the View tab and then click on the Show hidden files, folders, and drives radio button under Hidden files and folders.

show hidden files windows 7

Now navigate to the directory above and open the hosts file and make your changes.

edit hosts file

Note that this method for editing the Hosts file will not work. You will get a message saying you do not have permission to save in this location.

windows 7 hosts file

In order to edit it, you have to click on Start, type in Notepad and then right-click on Notepad and choose Run as Administrator.

run as administrator

Now navigate to the drivers/etc folder again and make sure to choose All files for File Types otherwise you won’t see the Hosts file.

view all files

Make your changes to the Hosts file and click File and Save to save all changes. Now you will not get the error about not being able to modify the Hosts file. Enjoy!

More posts from the Windows 7 Category

windows 7 jumplists

Create A Custom Jumplist in Windows 7

Enable and Disable Items in the New Context Menu in Windows

01Command_Prompt_in_Start_Menu.jpg

What the Windows 7 Power Report Tells You About Your Computer

Dexpot – Simple But Powerful Virtual Desktops For Windows

Popular Posts This Month

windows defender

Windows Defender vs. Security Essentials vs Safety Scanner

youtube ie11 freezing

How To Fix Flash Crashes in Internet Explorer 11

bitlocker error

Fix “This device can’t use a Trusted Platform Module” When Enabling BitLocker

  1. rtl says:

    Or use HostsMan. Less work.

    http://www.abelhadigital.com

  2. John Adams says:

    It is not necessary to check "show hidden files and folders" because "hosts" is not a hidden file.

  3. blinky says:

    It worked! Thanks!

  4. SnowNinja says:

    going to the folders is quick enough. Being thorough and including more than what should be is good as well!!!

    it reminds you where to access hidden files, if you don't access them often :) thnx Aseem

  5. wguru says:

    Nice addition to two other articles, ref:

    mvps.org/winhelp2002/hosts.htm
    mvps.org/winhelp2002/hostswin7.htm

    Seems odd that none of these tutorials/tips mention the default hosts file (as on my machine, I've never knowingly modified or even accessed) which currently reads much like a readme (saying the file is a sample file, plus I find no actual website entries to indicate any site is blocked).

    What are users to do (when manually adding blocked sites)? Maybe delete all the original text and then add sites?

  6. ginger315 says:

    It works right up till the point where you save, and it still says I don't have permission to save. Everything is exactly where the process states. I found everything, clicked everything, but I'm not able to save. Help!

  7. dmdufrene says:

    Keep reading Ginger, it doesn't work unless you open Notepad the way it shows after the point you stopped.

  8. derterifii says:

    Tells me "access denied." Am I missing something?

  9. jimmie_james_44 says:

    Yes, you need to take ownership of the file and give yourself full permission to modify the file. Once saved, then you revert it back to the attributes it had before you changed it, and revert ownership to the original owner. This is the only way to keep the file, because if you don't, windows will rewrite a new one to replace the one you just saved.

  10. AlexNet0 says:

    Actually, in addition, it's because the file is marked read-only by default. You must right click -> select properties, and un-check read only.

  11. techntuts says:

    Thanks for the useful post. Solved my Problem. :)

  12. mike d says:

    Awesome. Thanks a million!!

  13. kevinredden says:

    Hi.

    I have done everything that this thread has suggested, but I still keep getting a sample host file.

    Should I just paste my IP addresses underneath, delete the text, and paste them in? Or, is there a different thing I can try to find my real host file?

    Please help.

  14. randy blacklove says:

    Thanks, man! It really worked. ;-)

  15. mirage says:

    Access Denied!!!

  16. Richard Cummings says:

    I had done this many times in xp but was searching for modifying hosts file in Windows 7. Thx for the update I needed. Richard

  17. Spell says:

    Thanks a lot man !

    It's worked :)

  18. Muggl says:

    Hey guys,

    I have tried everthing to edit the file. I opend the notepad as admin or even activated the admin account to change the host… But whatever, it was worthless.

    Does someone have a new idea???

    Thax in advance

  19. Stephen says:

    Spybot S&D/symantec indicate that my hosts file has been altered. I tried to follow the instructions above, but am unable to locate the file in the system32driversetc folder (I do see the 4 other files: lmhosts.sam, networks, protocol, services). Is it possible to find the HOSTS file elsewhere?

  20. Grateful Child says:

    Just to say thank you sooooo much for this solution, …opening notepad as administrator. I spent three full hours with HP tech support in India with them finally telling me that I couldn’t edit my host file. I owe you a coffee next time I see you for sure…

  21. sona says:

    Hi

    I am trying to block a computer from Google Chat because all they do is Chat instead of working. Do I need to go through this and put in 127.0.01? Is there any easier way? I am not Tech savy.

  22. Hannah says:

    I can’t edit my host file for whatever reason. It’s not checked “read-only,” I’m running NotePad as an Administrator and opening the direct file and everything, but for whatever reason, it’s still a sample host file!! Please help me, I can’t access my main email and documents without Google sites (which are what aren’t opening; I use Chrome if that makes any difference).

  23. Elf says:

    its work..
    thx :)

  24. casey says:

    don't delete anything
    just add a line for the ipaddress that you want

    # localhost name resolution is handled within DNS itself.
    #127.0.0.1 localhost
    #::1 localhost
    test.yoursite.com 143.225.125.66

  25. Mike Buckland says:

    The following additional steps may be required to make the above work. Find the hosts file in Explorer (don’t use the shortcut), right click its name, select ‘Properties’, click the ‘Security’ tab, click the Edit button, select the user that is assigned to you, check the ‘Allow’ checkbox of ‘Full Control’ and click OK until you exit. There is no need to reboot.

  26. Ulderico Ze Machado says:

    I tried to elevate the both notepad and cmd but still no luck, so I edited the host file from safe mode, it works perfectly.

  27. Jerry says:

    Microsoft does it again. Preventing you permissions to edit files on your own computer. This is part of why I upgraded from Vista to XP when I got my last computer! After waiting a few years for Win7 to stabilize, I’m giving Win7 a shot now and the bad memories are coming back.

    As Hannah noted, for some reason even when “some” users make hosts writable and run notepad with Admin privilege, it still doesn’t allow updates! But the real question is, why does it work easily for some people’s PC and not for others? That seems beyond crazy.

    I’m on a plain vanilla, fresh load of Win7, so no excuses. I can’t even change the permissions or ownership to my user even though I verified that I have admin permissions. I’m going to try the Safe Mode Option and hope it works. You know, it really shouldn’t be this hard, it’s just plain sad…Where’s that extra copy of XP..hmmm.

  28. Jerry says:

    IF I DID IT….Well, since Safe Mode didn’t work. I decided to try hitting it from the User Accounts side of things. Accidentally found this obscure option in Control Panel\User Accounts and Family Safety\User Accounts called “Change User Account Control settings”.

    In here, you can dumb down your security to “Never Notify”. While this seems counter-intuitive, essentially, it not only does Not Notify you when you make “illegal” changes, it doesn’t prevent you from making those changes either! (It is my belief that different vendors might be setting this to other levels, which is why the above instructions worked for some people and not for others.

    Mine was defaulted to level 3 on a Toshiba laptop.) If not for windows fear-mongering about use of this setting, I would probably just leave at level 1 (so I could effectively pretend that there is no secret Administrator account controlling MY computer). But I will go ahead and set it back to their paranoid file access when complete, and recommend you do the same.

    Now I can finally 127.0.0.1 <a href="http://www.googleadservices.com” target=”_blank”>www.googleadservices.com that advertising juggernaut! Ingat!

    This frustrating moment brought to you by your friends at MS. (apologies if you didn’t enjoy the commentary)

  29. nope says:

    doesnt work.. still have no rights to the file… -1

  30. JB says:

    This does not work. Even running Notepad as Admin. When I go to save the /etc/host file it still forces a .txt extension. I cannot save the hosts file without a file extension, it forces an ext.

    Thinking of becoming a Mac fan……

  31. Dave M says:

    Instead of battling with windows notes to remove the .txt ext, use notepadd++, an excellent addition to your Windows setup :)

  32. John says:

    Hi,

    I have a windows 7 operating system and I found everything all the way to system32 but I did not find the etc file. May someone help me with this predicament? I am looking for the host file, by the way.

    Thank you!!!

  33. Charu says:

    Thank you for the detailed instructions. Very helpful!

  34. Jerry F says:

    Works great. Thank you for pointing out the location of the file and reveal hidden files and folders.

  35. ae123 says:

    This worked for me after 1)right-clicking on the file and allowing all users full control and 2)unchecking read-only.

    After those two steps I was able to do edit the host file.

    Thanks a lot!

  36. Rick W says:

    To avoid saving hosts as hosts.txt – simply type “hosts” with quotation marks. Same as it’s always been. :-)

  37. wesrve says:

    Hi, I wanted to block some sites and have edited with 127.0.0.1 followed by site name as below
    127.0.0.1 http://www.facebook.com

    but facebook is still accessible even after restarting and clearing the browser cache.

    Pls help me.

  38. CON57 says:

    This works well for blocking unwanted sites on children’s computers, but is it possible to hide that file and create a dummy file to put in its place?

  39. Don F. says:

    My experience same as ae123

    Notepad run as administrator did not Save, but if I first changed Hosts properties as shown below Save worked:

    Properties, Security (‘Authenticated Users’ set by virus), Edit, Full Control, Apply, then unclick Read-only

  40. Edy says:

    If you have Avira, then check the Settings. There is a checkmark that blocks you editing the host file.

  41. Sri says:

    Lower your security level.

  42. Memoooo says:

    Thanks, it worked!

  43. Don Edwards says:

    A lot of Windows struggles with the concept of a file name without an extension. But there’s an easy cheat.

    If you tell Notepad to save the file (or Save As and let the name be “hosts”) it will save “hosts.txt”.

    If you tell Notepad to Save As and specify the name as “hosts.” (note the period) then it will save “hosts”.

    (No, you don’t need/want the quotes.)

  44. Kuzzcor says:

    Click Start – search for “Notepad“, right-click and select “Run as Administrator“. This should launch notepad with elevated privileges. Now, open the host file from the File menu, edit and save.

    This should help!!!

  45. dt192 says:

    If you have Avira anti virus installed, you need to go into your settings general>security>system protection and uncheck protect windows hosts file from changes, otherwise when you try to save it just says access denied due to lack of permissions

  46. Brad Goetsch says:

    Thanks! I can never remember the path.

  47. Galin says:

    Except that doesn’t work. It still saves it as a .txt file which is not a hosts file.

  48. Adich says:

    Great tip. Thanks

  49. JessLeah says:

    Thank you, Kuzzcor !!!

    LOOK: “Now, open the host file from the File menu”
    i.e. Open notepad as instructed. In notepad click on File, now click Open… nav to hosts file. Voila!
    All better :)

    Kuzzcor says:
    January 21, 2013 at 8:38 am
    Click Start – search for “Notepad“, right-click and select “Run as Administrator“. This should launch notepad with elevated privileges. Now, open the host file from the File menu, edit and save.

    This should help!!!

  50. DJ says:

    Great instructions, thanks for posting.

  51. Mahesh says:

    Thanks :-)

  52. Neal C. Chambers says:

    So often when fixing problems on my computer (practically always) I end up with incorrect, misguided and irrelevant web sites trying to sell me something. So I was rather surprised that I got such clear, succinct and straightforward support from HelpDeskGeek.

  53. Neal C. Chambers says:

    Additionally, I did simply go to my windows folder and did a search for ‘hosts’ to come up with the proper file. Also, I did need to uncheck my Avira blocking any changes to the host file.

Leave a Reply