Petri

Easily Edit the HOSTS File in Windows 8

The Hosts file is a computer file used by an operating system to map hostnames to IP addresses. A Hosts file is a plain text file, and is conventionally named – you guessed it – “Hosts.” Today I’m going to walk you through the steps to edit the Hosts file in Windows 8 to help block dubious websites.

Note: We also have tutorial articles on how to edit a hosts file in Windows 7 and on a mobile device running Windows RT.

Sponsored

Using Hosts Files to Block Websites

The Hosts file contains lines of text consisting of an IP address in the first text field followed by one or more host names or fully qualified domain names (FQDNs). Each field is separated by white space (blanks or tabulation characters). Comment lines may be included; they are indicated by a hash character (#) in the first position of such lines. Entirely blank lines in the file are ignored.

For example, this is how my local Hosts file looks like:

Edit HOSTS File in Windows 8

The HOSTS file may present an attack vector for malicious software, and it may be modified by malicious software such as adware, computer viruses, or trojan horses. These applications may use it to redirect traffic from the intended destination to sites hosting malicious or unwanted content.

For example, lets say you wanted to prevent your computer (or someone else’s computer) from accessing a site called www.badsite.com. In that case, one of the simplest ways to easily stop the computer from reaching that site would be to edit the computer’s HOSTS file and insert a line such as this at the end of whatever is already listed in the file:   127.0.0.1        www.badsite.com

(Actually, one space is enough between the IP address and the FQDN of the target.)

Before making that change, if you ping www.badsite.com you’ll get what you see in the image below. (Honestly, I didn’t plan to get a reply — I just used that site name as an example! I really don’t know or care what that site has, and I do not imply that it is a bad site in any way. Although maybe it is. YMMV, so browse at your own risk.)

Edit HOSTS File in Windows 8

Sponsored

In Microsoft operating systems, the HOSTS file is located in the following location: C:\Windows\System32\Drivers\etc

  • To edit the HOSTS file you would use your preferred text editor program. Ideally, use Notepad.exe that is built in to Windows operating systems. Right-click on the HOSTS file and choose Open.

However, if you fancy other, more advanced text editors, you can try one of these two excellent freeware tools: Notepad++ and Notepad2.

  • Now, edit the file and add/delete whatever you want.

Note: Some Anti-Virus programs may monitor your HOSTS file. This is good, because they prevent malicious software from modifying it. However, now it too will be blocked. If this happens to you, consult with your AV help manual on how to overcome this.

If you try to edit the HOSTS file in Windows 8 as you would in previous operating systems and then attempt to save it, I found that even if you have Administrator rights you will be blocked from saving the file.

Edit HOSTS File in Windows 8: Notepad

  • Note that you need to select “All files” because the HOSTS file does not have any extension. If you don’t, it will be saved with the TXT file extension, and that is no good.

Edit HOSTS File in Windows 8: Notepad All Files

You will get an “Access is denied” error.

Edit HOSTS File in Windows 8: Error

Sponsored

Editing a HOSTS File in Windows 8: Method #1

Here is what you can do in order to edit the HOSTS file on Windows 8.

  • Copy the HOSTS file from the  C:\Windows\System32\Drivers\etc folder to your Desktop.
  • Open the copy from your Desktop in Notepad, and make all necessary changes.

Edit HOSTS File in Windows 8: Copy to Desktop

  • Edit the file, do whatever you need to do, then save and close the file back to the desktop.
  • Next, copy and paste the file to its original location.

Edit HOSTS File in Windows 8: Copy to Desktop

  • You will be asked if you want to overwrite the file. Choose Replace the file in the destination.

Edit HOSTS File in Windows 8: replace file

Windows will ask for Administrator permission; the changed HOSTS file will replace successfully the original.

Edit HOSTS File in Windows 8: permission

Editing a HOSTS File in Windows 8: Method #2

In this method, you can use Notepad and open it with administrative credentials, also known as elevated permissions.

  • In Start, find Notepad (it’s either there, pinned to the Start page, or simply type “Notepad” and press Enter). Once you find it, right-click it it; it will have a small check-mark next to it.
  • On the bottom of the screen choose Run as administrator.

Edit HOSTS File in Windows 8: Run as Admin

  • Now navigate to the  C:\Windows\System32\Drivers\etc folder and open the HOSTS file.
  • Make all necessary changes and save the file.

After the file was saved, if you ping www.badsite.com you will get this:

Edit HOSTS file in Windows 8: saved file

Of course you can edit the file as many times as you want to make necessary changes.

Tagged , ,

Sponsored
  • Pingback: Edit the HOSTS File in Windows 8 | IT (Systems,...()

  • Pingback: How to : การบล๊อคเว็บไซต์ด้วย Host File | IT-Clever บทความการใช้งานคอมพิวเตอร์()

  • Sasitharani Chandrasekaran

    it worked thank you

  • Shiann Taylor

    It doesn’t let you copy and past but nice try

  • wesley

    it still does not let me replace the existing file with the new one! :(

  • Pingback: Top 10 Petri IT Knowledgebase Articles of 2013()

  • http://www.petri.com Jeff James

    You probably need to make sure you’re doing that as an administrator. To do that: Right-click on the notepad icon and select “run as administrator” — then load the hosts file, edit, and then save.

  • Pingback: Edit the Hosts File in Windows 7()

  • Stargazer Giannis

    Still my access is denied even though I am the admin… any help?

  • Thinh Tran

    I’m running Windows 8.1 and it does not allow me to replacing the old hosts file with the new one, please help! :(

  • Andrew

    This doesn’t work. Access to file denied.

  • Prashanth M.S

    It worked for me too. Thanks.

  • SeriouslyWeb.com

    If you’re still getting issues replacing, you need to use Method #2 – you can simply right click Notepad from Start, or somewhere in the tiled section of Windows 8, and Run as Administrator – then be sure to do everything directly through Notepad – will work for you

    http://www.seriouslyweb.com

  • Jude8

    when I edit and save my hosts file, it creates a new hosts file in the destination as ‘hosts.txt’ it never used to do this. I save it as all files so I don’t know what’s going on.

  • Jude8

    I used method #2

  • Carl Floyd

    So did this for youtube.com and http://www.youtube.com, pinging either goes to 127.0.0.1, but if I browse to it via IE or Chrome, I am able to get to the website

  • Carl Floyd

    I had to reboot in order for it to take effect.. working now

Join The Conversation

Sponsors

Sponsors