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 from 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 the built-in Screen Time app) 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. 


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 scan your Mac for intrusive agents manually. It then allows you to remove it with another click. However, it also has a setting that will enable 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 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 to blacklist adult sites, but who said you couldn't modify it to block any site?

  1. Open System Preferences > Screen Time.
  2. Click on Content & Privacy.
  3. Choose Limit adult websites > Customise.
  4. Add a site you'd like to block.

Now, let's see what will happen when Safari opens that site. Hurray, it looks like we've blocked it!

How to block websites on Safari on your Mac using Terminal

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. 


The following method edits the host 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 host 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,  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.

  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:
  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. After typing in the IP address, hit Space 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: 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 Control-O and then Control-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:

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 X. Interestingly, it finds apps and plugins that I don’t normally see elsewhere. 


Block websites on your router

If you’re not comfortable editing the host 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 > Wi-Fi > 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 you to block specific sites and types of content according to a schedule you set. 

And browser extensions for Chrome, Firefox, and Safari can fulfill 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 properly assess it first. Read reviews of it and find out what other people think of it. Browser extensions are a favorite 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 host 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. 

Laptop with CleanMyMac
CleanMyMac X

Your Mac. As good as new.