thoughton:digitallife banner
about downloads imagery work
-- How To... --

Blocking a website with /etc/hosts in OS X


In an article on parental control of OS X, namely blocking children from accessing myspace.com, Dave Taylor proposes using the /etc/hosts file to accomplish the task. While experimenting with the method I found that I was unable to control the process, no matter what the contents of /etc/hosts.

After much trial and error I discovered that it is the lookupd process that needs to be restarted in order to respect changes to the /etc/hosts file. A reboot will accomplish the same thing, but twiddling my thumbs for several minutes through a shutdown and startup routine was not an acceptable solution.

In case anyone else has the same problem, here is the breakdown of this two-step process:

The default /etc/hosts file looks like this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

To block both http://myspace.com and http://www.myspace.com add a line such as 127.0.0.1 myspace.com www.myspace.com. Fire up Terminal.app and enter these commands:

sudo pico /etc/hosts
(use the down arrow to move the cursor to the end of the file)
127.0.0.1 myspace.com www.myspace.com
(ctrl X, Y to save and exit)

Now you need to fire up Activity Monitor (Located in OS X's /Utilities folder) and force quit the process named lookupd. You will need to enter your administrator password.

Fire up a web browser and enter http://www.myspace.com. You should now find that the browser is redirected to the localhost at 127.0.0.1. This will be the contents of OS X's /Library/Webserver/Documents/ folder.


Reversing the procedure

First you need to remove the myspace line from /etc/hosts. Head back to Terminal and reissue the pico command you used earlier:

sudo pico /etc/hosts

And delete the myspace line. Once again, hit ctrl-X, Y to save and exit.

You now need to again launch the Activity Monitor and force quit the process named lookupd. You will need to enter your administrator password again.

Open up a new web browser window and enter http://www.myspace.com. The browser should once again connect as usual.


Posted on 7 March 2006, to How To... | Mac OS X

Related entries

Goodbye ServuStats - 2 March 2005
Retrofit your website for smartphone/PDA access - 19 December 2005

Trackback Pings

TrackBack URL for this entry:
http://thoughton.co.uk/cgi-bin/mt-tb-dlosx.cgi/202

Comments

An excellent clarification of the process. I've amended my original article! :-)

by: Dave Taylor at March 7, 2006 3:56 AM

Subscribe to comments

Enter your email address in the box below to receive an email notification whenever a new comment is posted to this entry.

Email address:

Post a comment










Remember personal info?


Click a smiley!
:) ;) 8) :| :(
:P :X :? :mad: :D
:o :cry: :shock: :blush: :roll:



Security code
Please enter this security number in the space below (this prevents automated responses).



Category icon Sponsors