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. 

Tip

Before we start. If your main reason for blocking websites is to prevent other users of your Mac from visiting sites that may be insecure or from which they may download malware, you should think about installing an anti-malware tool. I recommend CleanMyMac X. It allows you to manually scan your Mac for intrusive agents. It then allows you to remove it with another click. However, it also has a setting that allows you to configure it to run in the background and automatically check for malware in real-time. If you have multiple users using your Mac, it’s a great way of making sure they don’t accidentally download something that could harm your computer.


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.

How to block websites on your Mac with parental controls
  1. Click on the Apple menu and choose System Preferences.
  2. Select Parental Controls.
  3. 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).
  4. Choose Content & Privacy and then press Turn On.
  5. Select Content and then choose from the options under Web Content.
  6. If you choose to allow access to only specified sites, you will need to paste or type in the URLs of those sites.
  7. 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. 

IMPORTANT

The following method edits the hosts file on your Mac. This is the file web browsers use to find websites that you want to visit. Changing the file could cause significant problems, including making the web completely inaccessible. So, you should only use it if you are confident in Terminal. And, you should back up the hosts file first. Here’s how to do that.

  1. Go to Applications>Utilities and double-click Terminal to launch it.
  2. Type: sudo /bin/cp /etc/hosts /etc/hosts-original
  3. 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.

How to block websites on Safari on your Mac without parental controls
  1. Type: sudo nano /etc/hosts
  2. 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.
  3. Type: 127.0.0.1
  4. 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.
  5. 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
  6. Press Return.
  7. Type: 127.0.0.1 again, then space, then the next URL, remembering that if you want to block subdomains or directories, you will need to type those separately.
  8. Hit Return.
  9. Repeat steps 7 and 8 until you have typed all the URLs you want to block.
  10. When you’re finished, press Ctrl+O and then Ctrl+X to save the hosts file and then close it.
  11. Type: dscacheutil -flushcache then 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:fe80::1%lo0 facebook.com

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.

How to block sites via browser extensions

Block websites on your router

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.

  1. 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’.
  2. Type or paste the URL into your browser's address bar.
  3. Type in the admin name and password for your router when requested. (It may be on a sticker on the router.
  4. Navigate to the Settings page.
  5. 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. 

CleanMyMac X CleanMyMac X
CleanMyMac X

Your Mac. As good as new.