Block Access to Websites on a Mac by Modifying /etc/hosts

It’s easy to block incoming connections on a Mac with the builtin firewall. Blocking outgoing connections to websites from your browsers or applications is a little more difficult. You could use an app like LittleSnitch but that is honestly overkill.

If you are comfortable with using Terminal then you can simply edit your hosts file to prevent your system from reaching out to specified sites.

The following example would prevent access to the Panic.com website and also block the Panic app “Transmit” from contacting the Panic website for updates etc.

How To

1. Open the Terminal.app (Applications/Utilities)
2. Paste the below into Terminal and hit enter

sudo nano /private/etc/hosts

You will be prompted for your password since ‘sudo’ invokes administrative privileges.

3. Go all the way to the end of your hosts file
4. Paste the below into the hosts file and edit the domain (website) as needed for your site. Do not change the 0.0.0.0’s.

##
# Block Access to Websites
#
0.0.0.0 panic.com
0.0.0.0 www.panic.com
0.0.0.0 http://panic.com
0.0.0.0 https://panic.com

5. Save (control-x) your changes
6. Paste the below into Terminal and hit enter

sudo dscacheutil -flushcache

Now all the traffic that your Mac sends the the domain you specified will go to the IP address of 0.0.0.0 which is nowhere!

Refresh your browser and verify access is no longer available.