How to block a website on a Mac, in every browser
In short: Screen Time can block a website in Safari with nothing to install. The hosts file blocks it in every browser and app, but you type each address by hand in Terminal. A firewall rule blocks a domain and all its subdomains in every app, for an hour, a day or for good. Which one fits depends on who you are blocking it for, and whether they use Safari.
With Screen Time, for Safari
Screen Time is built into macOS and needs no Terminal.
- Open System Settings › Screen Time. If you are setting this up for a child in your Family Sharing group, choose them in the Family Member menu.
- Click Content & Privacy, then App Store, Media, Web, & Games. Older versions of macOS call it Store, Web, Siri & Game Center Content.
- Next to Access to Web Content, choose Limit Adult Websites, then click Customize.
- Click the add button under the Restricted list, type the website's address, and click Done.
(Apple)
For a young child, Allowed Websites Only works the other way round: nothing opens except the sites on the list.
Two things to know. Apple lists this setting under Safari, and other browsers handle their own browsing, so test the block in every browser installed on that Mac. And it covers websites, so an app with its own connection to the same service, such as a desktop chat or video app, is a separate matter.
With the hosts file, for every app
The hosts file is a short list that macOS checks when any app looks up a name. Point a name at an address that leads nowhere, and no browser or app on the Mac can reach it. In Terminal:
sudo nano /etc/hosts
Add a line for each name at the end of the file, for example:
0.0.0.0 example.com
0.0.0.0 www.example.com
Save with Control-O and Return, quit with Control-X, then clear the Mac's lookup cache with sudo killall -HUP mDNSResponder (Apple).
It works in every browser, and it costs nothing. The catch is that every name needs its own line: blocking example.com doesn't block www.example.com, m.example.com or any other subdomain. There is also no timer and no record of what was stopped. Our hosts file guide covers it step by step, with how to undo it.
With a firewall rule, for every app and subdomain
An outgoing firewall can block by domain for the whole Mac or for one app. In Ranger:
- Choose File › New Rule… (Command-N), or click Add Rule… in Rules.
- Leave the action on Block. Under For, keep All apps, or choose One app to block the site only in, say, one browser.
- Under Where to, choose A domain and its subdomains and type the domain, such as
example.com. - Under Lasts, choose Until removed, 1 Hour or 24 Hours.
The rule covers every subdomain, in every browser and every app, and each blocked attempt shows up in Traffic, so you can see what tried to reach the site. When you create a new profile, Ranger also offers a Work starting point that closes social networks and video sites; you then remove the ones you need in Rules.
If the person using the Mac has a standard account and you are the administrator, they can see Ranger's rules but not change them.
Little Snitch and LuLu can block by domain too. LuLu's maker notes that its host-name rules only work for apps that use Apple's networking frameworks; for other apps, such as Chrome, it matches IP addresses.
What doesn't work well
A browser extension blocks the site in that one browser, and whoever you are blocking it for can often switch the extension off.
Your router, if it can block sites, covers every device at home, but not the Mac when it's on another network.
Blocking a name doesn't follow the content. A site that moves to a new domain, or a mirror of it, needs its own rule, whichever method you use.
If you are blocking a site for yourself, to stop reaching for it, a rule with a time limit suits that: block it for an hour, and decide again when the hour is up. Ranger's trial lasts 14 days, with every feature, and needs no email or card.