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 66.220.158.70. Your computer will then connect to this numerical IP address and access the website.
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.
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.
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:
C:\Windows\System32\Drivers\etc\hosts
(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’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:
C:\Windows\System32\Drivers\etc\hosts
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: