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.
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
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.
You will get an “Access is denied” error.
Here is what you can do in order to edit the HOSTS file on Windows 8.
Windows will ask for Administrator permission; the changed HOSTS file will replace successfully the original.
In this method, you can use Notepad and open it with administrative credentials, also known as elevated permissions.
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.