How to block websites on your Mac
Whether you administer multiple Macs for a company or organization or you just want to stop children in your household accessing sites intended for adults, there is likely to be some time when you want to block websites on a Mac. Apple’s parental controls (in Screen Time in macOS Catalina) can help, but they can also be a bit of a blunt tool and there may be occasions when you want to block websites on Safari on your Mac without parental controls. We’ll show you how to do both in this article.
How to block websites on your Mac with parental controls
In previous versions of macOS, there was a separate Parental Controls pane in System Preferences. It’s now hidden away in the Screen Time section, but the options are still the same. Sadly, those options aren’t very refined. You can either allow access to all websites, block ‘adult’ sites, or only allow access to specific sites. There’s no option to block sites you specify. Here’s how to restrict access.
- Click on the Apple menu and choose System Preferences.
- Select Parental Controls.
- From the dropdown menu at the top left of the window, choose the user account for which you want the controls to apply (only Standard accounts are shown here, so if you can’t see the account you want, go to Users & Groups and change its account type to Standard).
- Choose Content & Privacy and then press Turn On.
- Select Content and then choose from the options under Web Content.
If you choose to allow access to only specified sites, you will need to paste or type in the URLs of those sites. Close System Preferences.
How to block websites on Safari on your Mac without parental controls
If you want to block specific websites in Safari, or any other browser you use on your Mac, you’ll need to try a different approach. If you’re comfortable using Terminal, you can use Unix commands.
- Go to Applications > Utilities and double-click Terminal to launch it.
sudo /bin/cp /etc/hosts /etc/hosts-original
- Hit Return and type in your admin password when prompted.
You now have a backup of your hosts file, so if anything does go wrong, you can restore that and regain access to websites. To block specific websites in the hosts file, follow the steps below carefully. It’s worth noting that when you type in a URL, only that URL is blocked. So, for example, if you type in Facebook.com, the ‘www’ version of the domain won’t be blocked. To block both, you need to type both URLs separately. Similarly, subdomains aren’t blocked, so mobile versions of sites (which usually start ‘m.’) and login pages that have a separate subdomain won’t be blocked. You will need to type those URLs separately, too.
sudo nano /etc/hosts
- Make sure the cursor entry point is beneath all the text on screen on a new line. You must not change any of the text already on screen.
- That IP address is the local IP address, if any website is directed there, it won’t load, so now we need to direct those sites we want to block to that IP address.
- Hit Space after typing in the IP address and type in the URL of the site you want to block. Make sure you type it rather than paste it because pasting can introduce hidden characters that could cause problems
- Press Return.
127.0.0.1again, then space, then the next URL, remembering that if you want to block subdomains or directories, you will need to type those separately.
- Hit Return.
- Repeat steps 7 and 8 until you have typed all the URLs you want to block.
- When you’re finished, press Ctrl+O and then Ctrl+X to save the hosts file and then close it.
dscacheutil -flushcachethen hit Return. That flushes the cache, meaning the web browser will have to refer to the hosts file.
The above steps will block the IPv4 versions of sites in all browsers, but not the IPv6 versions. If you find a site is still accessible, it may be connecting via IPv6. To block that, say for Facebook, type:
How to block sites on Mac with Screen Time
Screen Time was added to macOS fairly recently. And while its purpose is to limit website activity, it can just as effectively block sites from opening. The solution works for all browsers. It was originally meant for blacklist adult sites but who said you can't modify it to block any site?
Open System Preferences > Screen Time.
Click on Content & Privacy.
Choose Limit adult websites > Customise.
Add a site you'd like to block.
Now, let's see what will happen when Safari opens that site. Hurray, looks like we've blocked it!
How to block sites via browser extensions
Certain sites keep popping up on your Mac because you have previously installed them as extensions. It’s no news that extensions may have double-purpose. You may block such sites that bombard you with ads by disabling the extensions on your Mac.
My favorite way to get rid of extensions, is again, to use CleanMyMac. Interestingly, it finds apps and plugins that I don’t normally see elsewhere.
- Get a copy of CleanMyMac — there is a free version you can download
- Click Extensions in the sidebar
Block websites on your router
If you’re not comfortable editing the hosts file in Terminal, you may also be able to block websites on your broadband router, depending on its make and model. To access your router’s settings, do the following.
- Locate the router IP address. It may be on the bottom of the router itself. If not, go to System Preferences > Network>Wifi > Advanced and click TCP/IP. Not the IP address next to ‘Router’.
- Type or paste the URL into your browser's address bar.
- Type in the admin name and password for your router when requested. (It may be on a sticker on the router.
- Navigate to the Settings page.
- Look for options to block sites and type in the URLs of the sites you want to block.
Block websites using third-party software
There are a number of third-party apps and browser extensions that allow you to block specific websites or types of content. For example, Focus allows to you to block specific sites and types of content according to a schedule you set.
And browser extensions for Chrome, Firefox, and Safari can fulfil the same function, although these usually block access to sites you specify permanently, rather than on a temporary basis.
When you choose a browser extension, you should take care to properly assess it first. Read reviews of it and find out what other people think of it. Browser extensions are a favourite way for malware distributors to spread adware and potentially-unwanted programs, and that’s the last thing you want to install on your Mac.
There are several ways to block websites on your Mac. The simplest is to use Screen Time (or Parental Controls if you’re running an older version of macOS). However, that is a very blunt tool and doesn’t allow you to specify which sites to block. So, if you want to block specific sites, you will either have to edit the hosts file in Terminal following the steps above, or use a third-party app or browser extension. If you’re worried about websites pushing malware onto your Mac, you can use CleanMyMac X’s real-time protection tool to keep it safe.