Blocking Facebook with your hosts file

In light of news regarding privacy and Facebook, I looked into a way to keep my web browsing from connecting with FB servers - my effort to be less trackable.  This is a heavy handed domain blocking approach and will break your Facebook.  Read here for information about manipulating your hosts file.  If you are not a Facebook user then you gain a kernel of privacy.

Edit:  This can be achieved with a uBlock for Firefox and Chrome.  I was not able to block Facebook domains using uBlock for Safari.

This will work on any OS with a HOSTS file

1.  Go here - https://github.com/jmdugan/blocklists/blob/master/corporations/facebook/all

This wonderful human posted many (I didn't check if it is all) domains associated with Facebook.  Thank you poster!

2.  Save the contents of file in a text file.

3.  Change all of the 0.0.0.0 to 127.0.0.1.  Use Sed ...

Open the file in terminal and run

sed 's/0.0.0.0/127.0.0.1/g' file from step 1.txt > file you create for step 3.txt

Edit: Don't use spaces.  It is workable to use spaces it just complicates things slightly.

4. Copy the contents of 'file you create for step 3.txt' and paste them into /private/etc/hosts

Done.  Now attempts by Facebook for tracking you through social media plugins/comment systems on your favourite websites will be routed to the localhost, your computer.


I tried this hosts intervention with the 0.0.0.0 + the domains (i.e. 0.0.0.0 facebook.com and 0.0.0.0 www.facebook.com).  Both Safari and Firefox ignored the change.  Only when changing 0.0.0.0 to 127.0.0.1 would it work.

As of writing this worked for Mac OS 10.3.4.

Comments