There are several reasons why you might want to block certain websites on your computer. Some websites could be spreading viruses, contain explicit content or even be trying to steal your personal data. While you may well be more than capable of avoiding these websites, but that doesn’t stand true for everyone who uses your device. In such cases, it might be best to block certain websites.
How to Block Any Website On Your Mac
Make sure you have administrator access to your Mac.
Now open Terminal.
You can find it under /Applications/Utilities/Terminal.
Type sudo nano /etc/hosts and press enter.
Enter the user (login) password when prompted.
This will open the file /etc/hosts in a text editor. Type the name of the website in a new line in this format “127.0.0.1 www.blockedwebsite.com” (minus the quotes). For each website you want to block, start a new line and type the same command with only the name of the website being replaced.
When done, press ctrl+x and then Y to save changes.
Now key in the command sudo dscacheutil -flushcache and press Enter or restart your machine to make sure the websites are blocked.