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:
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.)
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.
- 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.
- 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.
You will get an “Access is denied” 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 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.
- You will be asked if you want to overwrite the file. Choose Replace the file in the destination.
Windows will ask for Administrator permission; the changed HOSTS file will replace successfully the original.
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.
- 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:
Of course you can edit the file as many times as you want to make necessary changes.
More in Windows 8
Microsoft Acknowledges Office Zero-Day Flaw Affecting Windows Diagnostic Tool
May 31, 2022 | Rabia Noureen
How to Achieve World-Class Windows Patching Like a Pro
Aug 3, 2021 | Michael Reinders
Microsoft’s PrintNightmare Patch Not Effective Against Vulnerability
Jul 7, 2021 | Brad Sams
How to use the Windows Recovery Environment
Apr 21, 2021 | Michael Reinders
Microsoft’s New Browser Ships in January with New Icon and More Privacy
Nov 4, 2019 | Brad Sams
Microsoft Edge Takes Another Step Towards General Availability
Aug 20, 2019 | Brad Sams
Most popular on petri