Search

Top Posts

Comments

  • TvvitterBug: Nice article! I think the Twitter client landscape has really changed in 2010. New approaches and design...
  • DistortedLoop: I’ve been putting electronics in ziplock bags for years as a quick and dirty water-RESISTANT...
  • inket: Underwater pictures ? ^^
  • echo_host: Im running 10.6 and noticed that nothing was working, in apps or in terminal. I found out you need to...
  • Felipe: Hi, i have the same problem that ronan. I have 21 cycles, 3 months ols and a 95% of capacity. I’ve done...

Categories

Recent Posts


Block access to specified sites by modifying /etc/hosts

We’ve received several questions asking how to block specific sites from being accessed directly on the Mac. The frustration seems to lie in how easy it is to circumvent the typical measures, such as setting Parental Controls and blocking sites in Safari, only to have them accessed in Camino or Firefox. Well, a quick and efficient way to block access to specified sites is by editing the /etc/hosts file, which has the added bonus of providing system wide results. Whether it’s children or your roommate who you’re trying to stop from visiting a particular website, here’s how to do it.

Block access to websites on a Mac

Editing /etc/hosts

1) To edit the hosts file and add a new entry, open up your Terminal and type the following (You’ll be asked for your root password because this is a system file):
sudo nano /etc/hosts
2) This will bring up a screen that looks a lot like the one below, notice that myspace.com has been added at the bottom as a site we want to block. To block any other site, simply type it in the same fashion. You can have as many sites map to 127.0.0.1 as you want:

3) Now save the file in nano by hitting control-o and the return key.

How this works: you are now telling your Mac to send requests for MySpace.com (or whatever site you listed) to 127.0.0.1, your local machine. This completely blocks the MySpace.com address from being loaded in any web browser. (Note that if someone is savvy enough though they could access the blocked site through a web proxy). If you really want to be crafty and have Personal Web Sharing enabled, you could put up a simple webpage for people to see when they try to access the blocked sites.

Confused? Want a visual walkthrough? Take a peak at MurphyMac.com’s videocast showing how to edit /etc/hosts. MurphyMac also discusses other uses for the hosts file, such as setting shortnames to access local servers, check out the videocast here: MurphyMac’s videocast of hosts file usages

Posted by: Editor

Share

Save big on Mac Deals from Amazon.com

Comments:

Comments: 16

Comment from SnowTheInformer
Time: March 19, 2007, 1:03 pm

Your method works great for Mac’s and Linux machines, but you can do it on a Windows PC too, this link will show you how:

http://www.allthingsmarked.com/2006/08/28/howto-block-websites-using-the-hosts-file/

Comment from GreenAlien
Time: March 19, 2007, 2:03 pm

Blocking MySpace, LOL!

Comment from pbhj
Time: March 19, 2007, 9:36 pm

Like hmmm how ancient is this technique!! I’ve been blocking internet hosts using /etc/hosts (or the windows equiv.) for about 8 years and it was already prolific back then.

I seem to remember something about using 0.0.0.0 instead (or was it the other way?).

Comment from web hosting
Time: March 19, 2007, 9:37 pm

that’s so last millenium

Comment from Paco
Time: March 20, 2007, 12:08 am

try
http://someonewhocares.org/hosts

you’ll find more information about hosts files and a very nice list of sites to block…

Comment from hmills
Time: March 26, 2007, 2:36 pm

simple enough

Comment from halfbuiltrobot
Time: December 24, 2008, 11:30 am

Will this work if you wanted to block a specific page on a site? without blocking the hole site.
example: myspace/yoville.com, so the myspace page could be viewed but not the link to the application on myspace.

sorry if that makes no sense :)

Pingback from true false maybe » Giving up Reddit for Lent
Time: February 24, 2009, 11:06 am

[...] how you can do it too: Windows | OSX | [...]

Comment from girlfriend is on myspace too much
Time: March 2, 2009, 4:31 pm

I was able to block the site but wanted to unblock it to make sure I could unblock if needed. How do you undo the block I deleted text and saved what now?

Comment from Jill
Time: March 25, 2009, 1:39 pm

I also want to know how to unblock if needed…

Comment from michael
Time: April 15, 2009, 8:53 pm

@Jill and girlfriend on myspace to much guy, to unblock all you have to do is go back into the command and delete the urls you put in and also the ip address to your computer and safe the file again and that worked for me, just double check if you remove access to a site or add it back to see if it worked i have a mac with file vault on and it did not work for me i tested it on another account with out it on and it worked fine.

Comment from Jon
Time: June 2, 2009, 7:48 am

Please help! Thanks for the step-by-step guide, unfortunately it doesn’t work. I am using OS 10.5.7, 2 GHz Intel Core 2 Duo, and don’t have fire vault on. After entering the Terminal, adding my password, the screen I get is similar to your example above, except that the title line reads Terminal – sudo – 80×24, and after the line that reads
::1 localhost
I have another line that reads
fe80::1%lo0 localhost
Followed by the lines I added such as
127.0.0.1 myspace.com
127.0.0.1 facebook.com
127.0.0.1 asx.com.au

I then re-started my computer, only to find that safari version 4 public beta and firefox I can still enter the websites. I know my command lines are saved as when I re-enter the Terminal my added lines immediately appear. I would really appreciate it if you could help.

Comment from Greg Anderson
Time: October 12, 2009, 4:02 pm

It’s easier to type
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
…into terminal and then you can edit the hosts file in TextEdit. WAY easier in fact! Terminal seems to act weird sometimes with the delete and backspace key.
To remove a site, just delete that line and then save.

Pingback from A Collection of 250+ Terminal Commands, Hacks, Tips and Tuts for Mac OS X
Time: November 11, 2009, 1:13 pm

[...] Block access to specified sites by modifying /etc/hosts [...]

Comment from Gary
Time: December 1, 2009, 9:57 am

I don’t have a password set on my system so when I type in nothing it just goes back to the command line again.
What type of password does it asks for? System?

Thanks

Comment from Carlos
Time: January 29, 2010, 8:53 am

How can I block the IP adress and block surfing using proxy?

Write a comment






March 19th, 2007