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.

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

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.

edit hosts file win8 2
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

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.