How to block access to websites in MacOS X

By marcain

Rate: (6 Ratings)

This article will show you how to block access to websites on your Mac.

Instructions

Difficulty: Moderately Challenging

Things You’ll Need:

  • A Mac running MacOS X with a system account and password
Step1
The MacOS X Terminal application *Advanced users can skip ahead to the quick instructions on Step 7.

The first thing we need to do is launch the Terminal application so we can work on the command line. To do this, navigate to and open the 'Applications' folder that is on your hard drive. Then scroll down and open the 'Utilities' folder that is contained within the 'Applications' folder. Run the Terminal application by double clicking its icon.

You should now have a new Terminal window open. Make sure it's selected so that you see the word 'Terminal' in the top left menu of your
desktop.
Step2
Before making any changes to system files it's always good practice to make a backup of the original file. Do that now by typing the following command in Terminal

sudo /bin/cp /etc/hosts /etc/hosts.backup

Hit 'Enter' and type in your password
Step3
Now that we have a backup of the original file, we can change the original by typing the following command in Terminal

sudo /usr/bin/pico /etc/hosts

Hit 'Enter' and type in your password
Step4
The command you ran above opens up the 'hosts' file in a text editing program called pico. Do not change any of the original text; instead, we will add text at the end of the file.

To move your cursor (the small rectangle in the window) to the end of the file, hold down the 'Control' key on your keyboard and then hit 'v' so they're both pressed at the same time. Hit 'Enter' a couple of times to give yourself some room to type.
Step5
In the next few steps, you will need to swap 'BLOCKEDSITE.COM' with the site you want to block.

Type in the following text but with the site you want to block

127.0.0.1 WWW.BLOCKEDSITE.COM
127.0.0.1 BLOCKEDSITE.COM

Now close and save the file by holding down the 'Control' key and pressing the 'x' key at the same time. Then type in the 'y' key and finally hit the 'Enter' key.
Step6
Now quit your web browser to clear its cache. Open the browser again and navigate to WWW.BLOCKEDSITE.COM or BLOCKEDSITE.COM. Unless you have your own computer setup to serve web pages, the browser will now complain that 'the Browser can't connect to the server'.

That's because we have configured the computer to redirect any browser request for BLOCKEDSITE.COM to your own computer. You might choose to setup your computer to serve a web page with an appropriate message such as 'Access Blocked'.

That's it. You don't need to continue with the advanced version of these instructions in Step 7.
Step7
Warning: This is a advanced version of the instructions in Steps 1-6.

Assuming you've backed up the original hosts file, run this from the Terminal

sudo /usr/bin/pico /etc/hosts

At the end of the existing text, add the IP address of the site you want the user redirect to, a space and then the site you want blocked, like this


127.0.0.1 WWW.BLOCKEDSITE.COM
127.0.0.1 BLOCKEDSITE.COM

Save the file. Clear the cache on your browser and then navigate to WWW.BLOCKEDSITE.COM.

Tips & Warnings

  • If you ever want to close pico without saving changes, hit the 'Control' key and press the 'x' key at the same time. Then type the 'n' key followed by 'Enter' . None of your changes will be saved.
  • If you ever want to undo the changes made above, run the following command in the Terminal application: 'sudo /bin/mv /etc/hosts.backup /etc/hosts'
  • You can redirect traffic to any website you want (instead of your machine) by replacing '127.0.0.1' in Step 5 with the site's IP address
  • You can add as many sites to the list that you want.

Comments

| View All Comments
rosindabow

rosindabow said

Flag This Comment

on 6/2/2008 I read the above instructions about how to block unwanted sites and they are perfect! Is it possible to do the same type of step-by-step instructions telling how to "undo" any sites you've blocked? I know you tell how to do it in a little blurb (run the following command...) but It would be of great help to us novice programmers if you again went step by step. The first section is so incredibly detailed and easy to use - thanks!

Post a Comment

POST A COMMENT

Request a New How-To Article

Looking for more How To information? Chances are there’s an eHow member who knows how to do what you’re looking to do. Submit an article request now!

eHow Article: How to block access to websites in MacOS X

Article By: marcain

marcain

Enthusiast Enthusiast | 1990 Points

Category: Computers

Articles: See my other articles

Related Ads