Skip to content

Instantly share code, notes, and snippets.

@franky47
Last active December 7, 2018 08:05
Show Gist options
  • Save franky47/6835b4a7ca5c072e4b75efa08bc40422 to your computer and use it in GitHub Desktop.
Save franky47/6835b4a7ca5c072e4b75efa08bc40422 to your computer and use it in GitHub Desktop.
Block undesired web services from even resolving their DNS

Blocking Facebook, Twitter and Google (analytics & ads)

This file blocks DNS resolution of various (undesired) web services at the machine level, therefore locking them out of any browser (and CLIs like wget and curl).

Why ?

  • Productivity and focus
  • Doesn't use browser extensions that can see all your traffic
  • Centralised location for blocking

How ?

Paste the contents of the hosts file in /etc/hosts (you'll need sudo).

Tested on macOS 10.14.1

# Block Facebook IPv4
0.0.0.0 www.facebook.com
0.0.0.0 facebook.com
0.0.0.0 login.facebook.com
0.0.0.0 www.login.facebook.com
0.0.0.0 fbcdn.net
0.0.0.0 www.fbcdn.net
0.0.0.0 fbcdn.com
0.0.0.0 www.fbcdn.com
0.0.0.0 static.ak.fbcdn.net
0.0.0.0 static.ak.connect.facebook.com
0.0.0.0 connect.facebook.net
0.0.0.0 www.connect.facebook.net
0.0.0.0 apps.facebook.com
# Block Facebook IPv6
fe80::1%lo0 facebook.com
fe80::1%lo0 login.facebook.com
fe80::1%lo0 www.login.facebook.com
fe80::1%lo0 fbcdn.net
fe80::1%lo0 www.fbcdn.net
fe80::1%lo0 fbcdn.com
fe80::1%lo0 www.fbcdn.com
fe80::1%lo0 static.ak.fbcdn.net
fe80::1%lo0 static.ak.connect.facebook.com
fe80::1%lo0 connect.facebook.net
fe80::1%lo0 www.connect.facebook.net
fe80::1%lo0 apps.facebook.com
# Block Twitter IPv4
0.0.0.0 twitter.com
0.0.0.0 www.twitter.com
# Block Twitter IPv6
fe80::1%lo0 twitter.com
fe80::1%lo0 www.twitter.com
# Block Google Analytics & Ads IPv4
0.0.0.0 googletagmanager.com
0.0.0.0 googleanalytics.com
0.0.0.0 www.googleanalytics.com
0.0.0.0 google-analytics.com
0.0.0.0 www.google-analytics.com
0.0.0.0 tagmanager.google.com
0.0.0.0 googlesyndication.com
0.0.0.0 doubleclick.net
# Block Google Analytics & Ads IPv6
fe80::1%lo0 googletagmanager.com
fe80::1%lo0 googleanalytics.com
fe80::1%lo0 www.googleanalytics.com
fe80::1%lo0 google-analytics.com
fe80::1%lo0 www.google-analytics.com
fe80::1%lo0 tagmanager.google.com
fe80::1%lo0 googlesyndication.com
fe80::1%lo0 doubleclick.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment