/etc/hosts will not update/refresh at all

Check your hosts file, because probably it's malformed. It should look similar to this one:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
127.0.0.1       youtube.com
127.0.0.1       www.youtube.com
255.255.255.255 broadcasthost
::1             localhost
 

Opening the file with sudo nano /etc/hosts it should have a trailing empty line. All entries for 127.0.0.1 should be added above the broadcasthost. The space between IP-address and hostname should be one tab: .

After writing the file to disk with nano, the changes should take effect immediately (usually without executing any dnscacheutil or killall commands). Check this with ping youtube.com.

Google Chrome is (probably) the only app which doesn't adhere properly (as a test in a VM revealed).


sudo killall -HUP mDNSResponder

No reboot required.

"It works!" for me, OS X 10.11.6


If the site has both IPV4 and IPV6 DNS (you can see this by entering the following in terminal, e.g. where google.com is the domain you are trying to block):

$ dscacheutil -q host -a name google.com

If the result looks like this:

name: google.com
ipv6_address: 2a00:1450:400f:80c::200e

name: google.com
ip_address: 172.217.21.142    

Then you will need to add a line in the hosts file to also block the IPV6 address.

The following worked for me.

127.0.0.1 localhost
127.0.0.1 google.com
::  google.com
255.255.255.255 broadcasthost

Afterwards, checking it in terminal again:

$ dscacheutil -q host -a name google.com
name: google.com
ipv6_address: ::

name: google.com
ip_address: 127.0.0.1