Windows 8 takes a new approach to the hosts file by default – it won’t allow you to block Facebook and other websites by modifying your hosts file. Luckily, there’s a way to bypass this restriction.
When you add certain website addresses to Windows 8’s hosts file, Windows 8 will automatically remove them, effectively ignoring your changes. Microsoft isn’t just doing this to annoy us – there’s a good reason for it.
What’s a Hosts File?
When you access a website, your computer contacts your domain name system (DNS) server and requests its numerical IP address. For example, Facebook.com maps to 188.8.131.52. Your computer will then connect to this numerical IP address and access the website.
Your hosts file is a file, local to your computer, that can override this behavior. By editing your hosts file, you can point Facebook.com at any IP address you want. Some people use this trick to block websites – for example, you could point Facebook.com at 127.0.0.1, which is your computer’s local IP address. When someone tries to access Facebook.com on your computer, your computer will attempt to connect to itself at 127.0.0.1. It won’t find a web server, so the connection will immediately fail.
Why the Restriction is in Place
Unfortunately, malware often edits the hosts file to add such lines. For example, the malware could point Facebook.com at a different IP address entirely – one run by a malicious organization. The malicious website could even be disguised as Facebook.com. A user would look at their address bar, see Facebook.com, and never consider that they may be looking at a phishing site.
To prevent this from taking place, Windows 8 (more specifically, the Windows Defender antivirus included with Windows 8) monitors your hosts file. When it notices that a website such as Facebook.com has been added to your hosts file, it immediately removes the entry and allows connections to the normal Facebook.com website.
This is actually an important security feature for many users that would never consider editing their hosts file. However, if you’re a tech savvy user that wants to edit your hosts file to block a website, you can disable this restriction.
Ways to Bypass the Restriction
Because this restriction is put in place by the Windows Defender (formerly known as Microsoft Security Essentials) antivirus included with Windows 8, you have several options for bypassing it:
- Exclude the hosts file from being monitored in Windows Defender – If you want to use Windows Defender instead of a third-party antivirus, this is your best option. This does mean that Windows won’t protect you from malicious hosts file entries added by malware, however.
- Install a Third-Party Antivirus – Many third-party antivirus applications won’t be as aggressive about policing your hosts file. Many, such as avast! and AVG, are free. When you install a third-party antivirus, Windows Defender will disable itself.
You can also disable Windows Defender entirely, but that isn’t a good idea unless you’re using a third-party antivirus. Even if you’re a careful computer user, having multiple layers of protection is a good security practice.
Excluding the Hosts File
To exclude the hosts file from being monitored in Windows Defender, first open Windows Defender – press the Windows key, type Windows Defender, and press Enter.
Click the Settings tab and select the Excluded files and locations category.
Click the Browse button and navigate to the following file:
(If you installed Windows to a different directory, start in that directory instead of C:\Windows)
Click the Add button and then click Save Changes to save your changes.
You may now edit the hosts file normally.
Editing Your Hosts File
You’ll have to edit your hosts file as administrator. If you open it normally and try to save it, you’ll see a message stating you don’t have permission to save a file in its location.
To launch Notepad as administrator, press the Windows key, type Notepad, right-click the Notepad application that appears, and select Run as administrator. (You can also launch any other text editor you prefer, such as Notepad++.)
Click File –> Open in the Notepad window and navigate to the following file:
You’ll have to select All Files in the file type box at the bottom of the open dialog or the hosts file won’t appear in the list.
Add a line for each website you want to block. Type the number 127.0.0.1, followed by a space or tab, and then type the name of a website. For example, the following lines would block both facebook.com and example.com:
Save the file after you’re done. Your changes will take effect immediately and the website will be blocked – no system or browser restart required.
Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.
- Published 08/23/12