How To Edit, Reset The Windows Hosts File

Martin Brinkmann
Mar 6, 2011
Updated • May 3, 2018
Tutorials
|
32

The question came just up again and I realized that I have never posted a tutorial about editing and reseting the Windows Hosts file. I'd like to take a look at the Host file's functionality first.

The Windows Hosts file can be used to block or redirect hostnames. A hostname is the core part of a web address or local address, for instance ghacks.net or localhost. Each hosts file entry specifies an IP address and a hostname, which basically tells the system that the hostname should be resolved with that IP address.

The DNS server, that is usually queried, is bypassed for all entries in the Hosts file unless hardcoded in the operating system.

Let me give you two examples where this may be beneficial: users could block known advertising companies or spammers by redirecting requests to the local PC. This basically loads nothing when a website tries to load an advertisement, popup or other element.

Another example highlights that the hosts file can be beneficial to web developers. Say you just moved your website to a new server and the IP changed in the process. DNS servers need up to 48 hours to propagate, which means that it is difficult to test the website on the new server after the move if the DNS server is still redirecting the request to the old server.

The web developer could assign the new IP address to the website to avoid the propagation issue. (Please see Work On Websites Before DNS Propagation for a detailed guide on that subject)

It has to be noted that the Hosts file can also be exploited by malicious software, either by redirecting the user from legit sites to questionable ones, or by blocking access to security software that they might need to remove those programs again from the PC.

The location of the Windows Hosts file

The Windows Hosts file is located under the following path:

%SystemRoot%\system32\drivers\etc\

The %SystemRoot% in the beginning is a variable that is set to the Windows directory. Most Windows users have installed the operating system on c:\windows which would mean that the hosts file can be found under c:\windows\system32\drivers\etc\hosts

It may be necessary to display hidden system folders if Windows Explorer is used to navigate to the folder.

A click on Tools > Folder Options in Windows Explorer and a switch to the View tab opens a configuration menu where hidden folders can be set to be revealed.

If you use Windows 10, select File > Change Folder and Search options instead and switch to the View menu then.

Locate "hide protected operating system files (recommended)" and "hidden files and folders" and make sure that the former is unchecked, and that the latter is set to "Show hidden files, folders and drives". The settings can be easily reversed this way when needed.

The Hosts file itself can be edited with any plain text editor, Notepad for instance which ships with Windows. You should check first if the Hosts file is write protected. This is done by right-clicking the file and selecting properties from the opening context menu.

Look at the attributes section of the General tab. The file is write protected if read-only is checked. If it is, remove the entry. If you keep the read-only setting it is not possible to edit or reset the hosts file.

Remember to set the read-only attribute again once you are finished to prevent third party editing of the hosts file.

hosts properties

The default Windows Hosts file has no active entries. Please note that a line beginning with # is a comment line which will not be executed or processed.

windows hosts file

Editing the Windows Hosts file

Take a look at the examples in the comments. The syntax is always the same, first the IP address that you want to redirect the hostname to, then the hostname separated by at least one space.

  • To add entries to the hosts file you would enter the IP address first in the next blank line, followed by a space (or by pressing tab) and the hostname (which can be a domain name or localhost).
  • To delete Windows Hosts file entries select the whole line and press the delete button on the keyboard. You may also add # in front of any line to make it a comment so that it is not processed but preserved.
  • To edit individual entries click in the line of the mapping that you want to edit and make the changes.
  • To reset the hosts file simply remove all lines that are not comments. Microsoft has created a Fix-Ii solution to reset the hosts file which can be used instead. Users just have to execute the program once they have downloaded it to the local system. The main benefit is that they do not need to go through the manual process this way.

Please note that you need to save the changes before they become available. In Notepad you would select File > Save from the menu to do that.

And that's how your edit and reset the Windows Hosts file. Please leave any open questions or comments in the comment section below.

Related articles

Summary
How To Edit, Reset The Windows Hosts File
Article Name
How To Edit, Reset The Windows Hosts File
Description
Find out what the Windows Hosts file is, what you may use it for, and how to edit it using built-in Windows tools or third-party software.
Author
Publisher
Ghacks Technology News
Logo
Advertisement

Previous Post: «
Next Post: «

Comments

  1. Madetohome said on March 4, 2020 at 8:30 pm
    Reply

    might be best to have 2 scratchpad scripts? 1 for depreciated and 1 for inactive? or 1 script that is commented to indicated what’s what

  2. Anonymous said on October 30, 2018 at 3:41 pm
    Reply

    I do what I want to do but I cant save it. It says: C:\Windows\System32\drivers\etc\HOSTS

    You are not allowed to open this file, ask the file owner or an administrator of the system even though I am the Administrator

  3. prithviraaj said on October 15, 2017 at 8:15 am
    Reply

    what if we don’t have permission to make changes to the computer while saving the edited format?

  4. Jevgenij said on July 20, 2017 at 9:35 pm
    Reply

    If ZoneAlarm is installed:
    Firewall page/Main/Advanced Button/Advanced Settings/UNcheck Lock Host File.

  5. Ancient said on October 20, 2016 at 8:21 pm
    Reply

    I have all these websites that are connecting to me. down.baidu2016.com / czzsyzgm.com and a whole bunch of others. This is a problem i assume, how do i fix this?

  6. lin said on April 5, 2016 at 3:11 am
    Reply

    change attribute is No avail, not necessary

  7. lin said on April 5, 2016 at 3:07 am
    Reply

    there are two notepad.exe in x64 windows,

    you must use full path c:\windows\system2\notepad.exe ,this one is 64 bit version,

    only type notepad whithout path may be launch 32 bit notepad.
    (c:\windows\syswow64\notepad.exe)

    “Run as administrator” just let you enforce launch 64 bit notepad.exe

    using 32 bit software to edit c:\windows\system32\drivers\etc\hosts

    the x64 system will automatic redirect to c:\windows\syswow64\drivers\etc

    and there is no hosts file.

    the GUI stiil display current folder is c:\windows\system32

    but the real folder is c:\windows\syswow64

  8. El Nino said on January 7, 2014 at 11:24 pm
    Reply

    THANKS … GENIUS :D

  9. Ricardo said on October 3, 2012 at 2:39 pm
    Reply

    I cant save it. What is the extension of the file?

    1. Martin Brinkmann said on October 3, 2012 at 5:27 pm
      Reply

      It has no extension

  10. Nikhil said on June 28, 2012 at 11:15 am
    Reply

    Hello

    I have an HTML file and i want to open it on IE9 by setting that file to host file..so how can i do that.

  11. Mike said on October 18, 2011 at 8:21 am
    Reply

    Thanks for the post, i noted that when i edit the hosts file with notepad it changes to a .txt file. is that ok or am doing something wrong.

    1. Martin Brinkmann said on October 18, 2011 at 8:42 am
      Reply

      You need to keep the original format of the hosts file without .txt extension

  12. will said on March 7, 2011 at 6:54 pm
    Reply

    sometimes viruses can alter the permissions on the hosts file and you need to reset it , here’s a quick batchfile to do so.

    @echo off
    ECHO Resetting permissions on HOSTS file…
    echo,Y|cacls “%WinDir%system32driversetchosts” /G everyone:f
    attrib -s -h -r “%WinDir%system32driversetchosts”
    ECHO.
    Echo Now edit the HOSTS file then save it.
    pause
    notepad “%WinDir%system32driversetchosts
    attrib +s +h +r “%WinDir%system32driversetchosts”

    1. Martin said on March 8, 2011 at 2:00 am
      Reply

      Nice tip Will, thanks for posting.

  13. randomhead said on March 7, 2011 at 4:06 pm
    Reply

    aah sorry ghacks! i meant yous guys honest!

  14. randomhead said on March 7, 2011 at 2:26 pm
    Reply

    nice to read , technical things the average user may not know of ! but handy for sure,, id love to see some more info on resetting different areas of win 7 64/32,, such as access permissions to drives as im sure mine have become corrupted somehow,,perhaps more tweaks to the firewall we can all do to secure it further too? :) such as disabling remote assist and remote desktop , which as a single use pc the average user has no need of , keep up the good work htg!

    1. Martin said on March 8, 2011 at 2:01 am
      Reply

      I think about it ;)

  15. Barbarosa said on March 6, 2011 at 7:42 pm
    Reply

    In my Vista 64 system, the hosts file itself does not have the read-only attribute set by default. Nevertheless, it *is* write-protected. It will not open in a text editor.

    I found out that it is the “etc” folder which is read-only, and I gained access to the hosts file by changing the folder attribute.

    1. Martin said on March 8, 2011 at 2:02 am
      Reply

      Thanks for the tip, something to look out for if you cannot edit the hosts file but it is not write protected.

  16. Toni said on March 6, 2011 at 6:11 pm
    Reply

    I think the easiest way to edit a windows hosts files is open notepad as administrator. Then open hosts file from the correct path (c:\windows\system32\drivers\etc\hosts). That’s all.

    1. Martin said on March 8, 2011 at 2:02 am
      Reply

      Interesting and definitely faster.

  17. Joe said on March 6, 2011 at 2:42 pm
    Reply

    I use HostsXpert to maintain the hosts file from MVPS as an adblocker. It blocks ads in all of the browsers I use (Firefox, Google Chrome, and, occassionally, IE or Opera). You can press a button in HostsXpert to check for an update to MVPS’s hosts file, another to download it and replace yours, it adds some great features to make it easier to edit your hosts file, and it’s portable. HostsXpert hasn’t been updated since 2008, but I’ve been using it with no problems on 64-bit Windows 7.

    HostsXpert: http://www.majorgeeks.com/files/details/hostsxpert.html

    MVPS Hosts: http://www.mvps.org/winhelp2002/hosts.htm

  18. sulasno said on March 6, 2011 at 3:20 pm
    Reply

    in addition to HostsXpert I also use BissHostsManager

  19. sulasno said on March 6, 2011 at 3:19 pm
    Reply

    in addition to HostsXpert I use BissHostsManager

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.