Use Terminal to Block Websites on Mac
Mac OS X has Hosts file just like Windows. We can edit Hosts via Terminal on a Mac to block specific websites that are not allowed to visit.
- To edit the hosts file and add a new blocking entry, open up your Terminal and type the following command line (You’ll be asked for your root password because this is a system file):
sudo nano /etc/hosts
- This will bring up a Nano box that looks like the one below. Yahoo has been added to block list as you can see. To block any other site, simply type it in the same format.
one line, one site. And don’t forget to add “www” if the URL has been prefixed with “www”, or it will not work with Safari.
- Click CTRL+X and Press Y in your keyboard to save modified buffer, and then press Enter to go back to Terminal.
- Please run the following command in Terminal to take the changes take into effect:
If you are using Mac OS 10.4.X, please type the following and press Enter:
lookupd –flushcacheFor Mac OS 10.5.X and later, it can be done by entering the following and press Enter:
sudo dscacheutil –flushcache
By modifying the Hosts file we can block any sites we want to on Mac. But we do not suggest it when you are not Mac savvy enough. There is an easy alternative for you: using Aobo Web Filter for Mac. It makes the blocking work more convenient and powerful.Download Aobo Internet Filter for Mac Free Trial Instantly!
Category: Filter Mac Learning Center