less than a minute read

How to block websites on Mac

I always need to block several websites on my Mac as part of my setup, and I’ve been using apps like SelfControl . I was recently curious about how it works, and after looking at the code implementation , I discovered it’s surprisingly simple.

SelfControl basically modifies the /etc/hosts file by adding entries that redirect blocked websites to non-routable addresses for a specific time period. But if you don’t need the time-based blocking, you can do this yourself by adding the domains along with their www variants:

0.0.0.0 tiktok.com
0.0.0.0 www.tiktok.com
::1 tiktok.com
::1 www.tiktok.com

0.0.0.0 twitter.com
0.0.0.0 www.twitter.com
::1 twitter.com
::1 www.twitter.com

0.0.0.0 x.com
0.0.0.0 www.x.com
::1 x.com
::1 www.x.com

This works because all domains you define will be redirected to non-routable addresses. The 0.0.0.0 is a non-routable address that effectively blocks the domain, while ::1 is the IPv6 loopback address that does the same for IPv6 traffic.

TipsMac