How to block access to Facebook and Twitter on your Windows PC using hosts file

Updated on September 2, 2017

Recently my son started to spend more time on Facebook. How much ever I tell him, he still uses it whenever I wasn’t at home. So I desperately wanted a quick trick to block Facebook on Windows (better if I can do it without installing a software) and here’s how it’s done. All you need to do is, just add few lines to your hosts File.

Advantage of Blocking websites using Hosts file

1. Easy to Use and Practical: No need to install any new software, as it might add to the system load and no need to mess with your firewall rules as well.

2. Blocking on all browser: This trick works uniformly across all the browsers in the system.

3. Blocking various websites: Besides Facebook and Twitter, you can block other websites too.

What is a Hosts file?

The hosts file is used to map hostnames to IP addresses. You can locate the file at : C:\Windows\System32\drivers\etc\hosts on your Windows OS.

Block Facebook and Twitter

Step 1: To access the hosts file, you need Administrator privileges. So open the notepad in Administrator mode.

Open Notepad with Administrator Privilege
Open Notepad with Administrator Privilege

Step 2: Now open the hosts file by navigating to the location as shown in the below image.

Open Hosts file in Windows using Notepad
Open Hosts file in Windows using Notepad

Step 3: Add the below lines to hosts file and save it.

127.0.0.1 www.facebook.com
127.0.0.1 facebook.com
127.0.0.1 twitter.com
127.0.0.1 www.twitter.com
::1 www.facebook.com
::1 facebook.com
::1 twitter.com
::1 www.twitter.com

Note: This trick might not work for websites that are served via HTTPs and IPv6 protocol, so you need to map Facebook to IPv6’s localhost notation as well.

Step 4: After adding entries to hosts file, you have to execute the below command as well.

Open your command line with Administrator privilege as shown in the below image.

Open CommandLine with Administrator Privilege

Execute the below command:

ipconfig /flushdns

Flush DNS through Command Line

Step 5: Now try accessing Facebook in any of your browser to only to see the message “Unable to connect”

Facebook Blocked Page in Browser

Explanation:

When the browser is requested to open a website, the system firstly check the site’s IP Address defined in the hosts file. If not available, then it takes help from the DNS.

Apparently in our case, the IP address of Facebook is 127.0.0.1 or commonly called the localhost. It means that the system will not load Facebook from its original IP address, rather just show a blank page with “Unable to connect” in Firefox, whereas “Internet Access is blocked” in Google Chrome browser.

The above trick can also be used in other operating systems like MAC and any flavors of Linux too.

Was this article helpful?

Related Articles

Comments Leave a Comment

  1. Not bad, but hardly an exhaustive list. Remember, these sites use various domains to spy on you. I’ll research more and report back. And yes, twenty years ago I was using HOSTS to block noxious sites at my cyber cafe. Now that I’m sitting at home criticizing everyone else, I thought I’d stop MyFace from harvesting my web browsing habits. I’ll find the Twaster bugs as well… good luck.

Leave a Comment