Block Facebook with a hosts file

The hosts file is a computer file used in an operating system to map hostnames to IP addresses. The hosts file is a plain-text file and is conventionally named hosts. (This file has no file name extension, it’s simply called hosts).

You can use a hosts file to block ads, banners, malware or specific websites like in this guide. This is accomplished by blocking the connection to these websites or files (specifically by redirecting any connection attempts back to the local (your) machine.)

Location of the hosts file

This guide will assume you are on a Windows OS. The easiest ways to locate the hosts file is to open the Run dialog (Windows button + R) or simply use the search box in Windows 7.

Type %SystemRoot%\system32\drivers\etc\ and press enter

Windows Run dialog

Editing the hosts file

You will now be in the folder containing the hosts file.

hosts file folder on a Windows 7 machine

Before you continue, make a backup of the hosts file by first selecting it, copying (CTRL + C) and pasting (CTRL + V) it in the same folder.

Now we want to edit it. Right click it and select Open, select Notepad and press OK.

hosts file

We are now editing the hosts file. Find the part where it looks like the following:       localhost

and add this:

It should look like this now:       localhost

Finishing up

Save the file and exit. Facebook is now blocked, enjoy your new found productivity!