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
- Open Terminal, in Applications, Utilities.
- Keep a copy of the file first:
Terminal asks for your administrator password. Nothing appears while you type it; press Return.sudo cp /etc/hosts /etc/hosts.backup - Open the file in the nano editor:
sudo nano /etc/hosts - Move to the end with the arrow keys. Leave the
localhostlines 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 - Save with Control-O and Return, close nano with Control-X.
- Flush the DNS cache, so no stored answer lingers:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder - 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
- www. and m. are names of their own.
youtube.comandwww.youtube.comare two entries. Short links likeyoutu.beorredd.itare different names altogether. - No wildcards. Each line names one host exactly.
*.youtube.comis not a pattern, so every subdomain you want gone needs its own line. - IPv6. A
0.0.0.0line only answers the IPv4 question. Where the site has an IPv6 address and your network uses IPv6, the browser can still get there. The::line closes that door. - Tabs that are already open. A loaded page stays on screen, and a browser may keep its connection for a moment. Reload the tab.
- Pages, not names. The file cannot block
youtube.com/shortsand leave the rest of YouTube. It is the whole name or nothing. - Only this Mac. Your phone and your other computers are not affected.
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 <<<
- Your password, once. It sets up a small helper (a LaunchDaemon) that may edit the file. The app itself runs with your normal rights.
- Only its own lines. The helper changes what is between
# >>> Not Nowand# <<< Not Now. Everything else in the file stays as it was, byte for byte, your own blocks included. When you unblock, its lines are gone. - The Mac keeps working. apple.com, icloud.com and local names ending in .local are never blocked, whatever is on the list.
- Nothing stays stuck. Quitting Not Now lifts the block. If the app crashes, the helper lifts it by itself after five minutes.
- A clock. By hand, for 25 minutes up to 4 hours, or on a schedule. “Okay, Now” lifts it with one click.
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.