Not Now

Not Now / Hosts file

Block websites with the hosts file on macOS

The oldest way to block a site on a Mac is still the one that reaches every browser. It takes a few minutes in Terminal and a little care.

Short answer: Open Terminal, run sudo nano /etc/hosts and add two lines per name, 0.0.0.0 youtube.com and :: youtube.com. Save, then flush the DNS cache with sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder. From then on, browsers on your Mac get an empty address for that name.

What the hosts file is

/etc/hosts is a plain text file that pairs addresses with names. According to its manual page (man 5 hosts in Terminal), macOS reads it through mDNSResponder and uses it for address lookups alongside normal DNS. Browsers ask macOS for addresses, so a name you point at 0.0.0.0 leads nowhere, in Safari and Chrome alike. We tested that on 23 October 2026, Chrome also with its own DNS client. Firefox reads the same file; our own test with it is still to come.

Step by step

  1. Open Terminal, in Applications, Utilities.
  2. Keep a copy of the file first:
    sudo cp /etc/hosts /etc/hosts.backup
    Terminal asks for your administrator password. Nothing appears while you type it; press Return.
  3. Open the file in the nano editor:
    sudo nano /etc/hosts
  4. Move to the end with the arrow keys. Leave the localhost lines at the top alone; the file itself says not to change them. Add your lines below:
    # my blocks
    0.0.0.0 youtube.com
    :: youtube.com
    0.0.0.0 www.youtube.com
    :: www.youtube.com
    0.0.0.0 m.youtube.com
    :: m.youtube.com
    0.0.0.0 youtu.be
    :: youtu.be
  5. Save with Control-O and Return, close nano with Control-X.
  6. Flush the DNS cache, so no stored answer lingers:
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  7. Reload the site in your browser. It should fail to connect.

To undo it, open the file again, delete your lines, save and flush once more. Or put the copy back with sudo cp /etc/hosts.backup /etc/hosts, as long as you have not changed anything else since.

Where it lets sites through

And there is no clock. The block stays until you edit the file again, which is fine for a site you never want back and tedious for one you only want gone in the mornings.

How Not Now does the same, safely

Not Now is a free menu bar app that writes these lines for you. You tick sites in a list, and it adds the 0.0.0.0 and :: lines for each name, with www., m. and known second names such as youtu.be. It flushes the DNS cache with the same two commands as above. Its section of the file looks like this:

# >>> Not Now >>> sites blocked while Not Now is on. Managed by the app: lines in here are overwritten.
0.0.0.0 youtube.com
:: youtube.com
0.0.0.0 www.youtube.com
:: www.youtube.com
# <<< Not Now <<<

Not Now has no network code, no account and keeps no statistics. To remove it, click “Remove Helper…” in its settings, which takes its lines out of the file, then drag the app to the Trash. Details are in How it works and the questions.

Last checked 23 October 2026, on macOS with the hosts file as Apple ships it.

Related