
I run a business and I don’t want people going on youtube or Face Book, is there any way I can block these sites for cheap? I have a mac and Safari.
NOTE: New method below.
Do you work in a retail store? I see teenagers on Facebook at the local mall or Best Buy all the time. Hilariously enough the employees at these stores are either annoyed…..or on Facebook themselves!
Onto your question. There is a simple way of blocking websites on a Mac. Simply modify a file called “HOSTS”. This file allows you to add as many websites to it as you want. You can either block the websites outright or have them redirect to whatever site you want. The procedure is ridiculously easy.
Here’s how:
- Click on Go at the menu bar.
- Go to Utilities and select Terminal in the window that opens. (without quotation marks)
- Type in “sudo pico /etc/hosts” (without quotations)
- You will be asked for you password. Enter it.
- Terminal will open the hosts file. Move the curser down to the end of it and enter in the following (without quotation marks):
“127.0.0.1 http://www.facebook.com”
“127.0.0.1 http://www.youtube.com”
And that’s it! Save the file and exit the terminal. When you’re done fire up Safari and try to go to facebook. You can’t!
EDIT! PLEASE FOLLOW THESE STEPS IF THE ABOVE DO NOT WORK!
Several people have told me in the comments below that the above did not work for them. I tried it on 10.5 myself recently and could not find a way to save the HOSTS file after it have been modified. So here is a workaround.
- Disregard the above.
- Click on Go at the menu bar.
- Go to Utilities and select Terminal in the window that opens.
- Type in sudo su. Press Enter.
- If at any point you’re prompted for a password please type it in.
- Type in echo “127.0.0.1 www.xxx.com” >> /etc/hosts (with quotation marks and substituting xxx with the site you want to block. Press Enter
- Type Exit. Press Enter.
- Close Terminal, restart your browser and you should be good to go!
Having other problems with your computer? Simply scan your computer for free to identify problem areas. Click here to start a free scan.

Posted in
April 20th, 2009 at 3:41 pm
this did not make a difference for me
April 21st, 2009 at 10:28 am
Hi Archie,
Sorry to hear that it didn’t work for you. Perhaps you missed a step? Make sure that you NOT include the quotation marks that are in the above article and that you save the file after you’ve added the lines. If it’s still not working try rebooting your computer.
Regards,
theFakeGeek
April 27th, 2009 at 1:04 pm
How you do block a site when someone searched via google and clicks on the cached link?
April 27th, 2009 at 3:50 pm
In that case you’ll need some sort of software that actually scans the page and picks out keywords. Take a look at parental control software.
April 28th, 2009 at 11:45 pm
I tried all of this for 6 different sites. It only worked for one of the sites. It was the 4th one that I typed in. I noticed that I put an extra w in all of the other addresses. I fixed this but that one site is still the only site that is blocked. Could it have something to do with the sites or am i still missing something?
April 29th, 2009 at 3:34 pm
Make sure that you put “http://” in front of the “www” for all of the addresses.
Hope that helps. :)
May 1st, 2009 at 12:34 pm
Hey,
It was all working for me up until you said in step 5 “move the cursor down to the end of it”. What does this mean? Cause you can just keep entering down that file forever. And how are u supposed to go about saving it? I just pushed command s and saved it so I think it saved but youtube is still not blocked?
May 2nd, 2009 at 4:44 pm
The whole “move the cursor to the end of the file” means that you should start your website entries AFTER all the other text in the file. Sorry about the confusion.
And perhaps I got a step wrong. I wrote the article out of memory. I’ll double-check next time I’m at a Mac.
July 8th, 2009 at 7:50 pm
You steps were very clear and everything seemed to work exactly as you described…except the sites aren’t blocked in safari, even after a restart. Any more hints and tips to get safari to block websites?
July 9th, 2009 at 2:55 am
This might work for entire domains, but what about a specific URL?
For exemple, could you block a personal page on myspace.com without blocking any other page on that same domain?
July 27th, 2009 at 6:14 pm
Hi there,
I’m so annoyed by a pop-up that continually comes onto my computer screen (Mac) when I press the center button on the mouse (as you would to bring up the calculator, calendar, temperature, etc).
The site is http://tag.contextweb.com and it’s usually followed by a million other characters.
If I had to try and trace back to the beginning of this problem, i’d say it was right after I installed the required software for my HP C4385 printer.
HP slowed down my old PC after a printer-related install and loaded it up with all sorts of marketing/advertising and user-tracking junk so I’m pre-disposed to wanting to blame them. I am SO frustrated because my new Mac is so much slower in general since installing the HP software, and now I have to deal with this annoying pop-up every time I use my calculator or calendar (roughly 1000 times a day).
I tried blocking the root site (http://tag.contextweb.com/) using the method outlined above. Thanks for the clear directions, but sadly it didn’t work for me. I’m wondering if there’s some other approach I should be taking given that this site actually appears out of nowhere — a browser launches seemingly on its own just by the click of the center mouse button. UGH!
Thanks for any insight,
Shannon
July 29th, 2009 at 9:26 pm
No I’m not that big of a Mac user. Sorry. Perhaps someone will see your post and will offer a suggestion.
July 30th, 2009 at 4:20 am
ok so i enter the code it tells me to enter my password nut when i try to type it in it dosent let me it is like terminal is frozen!!!!!!!!!!!!
August 5th, 2009 at 5:56 pm
i followed da steps until 4 rule i dont know why my password isnt working im not sure what password they are talking could you please make clear what password you use.
August 11th, 2009 at 2:56 pm
you were just a little off, but it is simple. Check this out and it works
http://osxdaily.com/2007/03/19/block-access-to-specified-sites-by-modifying-etchosts/
August 12th, 2009 at 7:19 pm
Thanks!
September 12th, 2009 at 11:03 am
Hi
Can you tell me how to save changes in terminal once I have put in a website? I have done everything you suggest by copying the address with 127.0.0.1 in front but I cant save it and thus the sites are still not blocked…please help.
September 12th, 2009 at 6:53 pm
If you goto File>Save that should allow you to save the file.
September 26th, 2009 at 6:37 pm
Mentioned cmd not worked………….
please help me.
September 26th, 2009 at 9:11 pm
I’ve duplicated your saving problem and modified the post above. Please follow the new directions and disregard the old ones.
Cheers.
September 28th, 2009 at 6:50 pm
Hi
I couldnt find the ‘Go’ section in the menu bar. Where are the utlitiies? its not in preferences.I really need to block fb on my computer. HELP!
- mobs
October 1st, 2009 at 2:44 pm
Hello Mobs.
On your dock you will see the “Finder” icon. It is a blue smiling face. Click on it. It will open a window. Inside this windows click on the “Applications” option in the left-side column. This will open the applications window. Then find and click on “Utilities” and follow the rest of the steps.
November 21st, 2009 at 9:07 pm
when i attempt to type in my pass word it wont let me, everything else worked in terminal upto that.
December 1st, 2009 at 11:02 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
December 5th, 2009 at 6:13 pm
I tried this many times for a single site, and it worked once. That time it did work, there was a bubble, so I clicked it, and then I quit Safari. After doing so, I opened the site again and it no longer blocked it. I tried the process again, both ways, and it still fails to block the website. Please help?
December 18th, 2009 at 11:15 am
What menu bar are you talking about? I’m new to Mac :( Where is “Go?”
December 22nd, 2009 at 12:26 am
I still need help…
After I enter my password, I get a line that says:
sh-3.2#
And I can type past that. I put in what you said, hit enter, and it went down to the next line and showed:
>
so I typed it in again, and it told me:
sh: echo 127.0.0.1: command not found
So, I have two questions, What should I type when given “sh–3.2#” and what do I do about the command not being found?
P.S. Thanks a load for this help!
December 22nd, 2009 at 12:39 am
I found the problem. In “echo “127.0.0.1 http://www.xxx.com” >> etc/hosts, the quotation mark before echo shouldn’t be there.
Thanks again for the article!
December 27th, 2009 at 3:11 pm
Your administrative password that you set when you first setup your mac.
April 17th, 2010 at 3:03 pm
Is there an easier way?
May 19th, 2010 at 7:22 pm
So on my terminal it says -bash: etc/hosts: No such file or directory after i hit enter…help?
May 29th, 2010 at 12:55 pm
Hi- I blocked some stuff off using the method- that I need access to again- Is there a way to do that?
July 2nd, 2010 at 8:26 pm
Most likely. If you find it please let me know. :)
July 10th, 2010 at 12:14 pm
I tried your (second) set of instructions, and it worked great. But I had to each site with both “www” and without it (maybe if I had included http:// the redundancy wouldn’t be necessary?)
I noticed there was an extra quote before “echo” that you’re not supposed to add, which could cause confusion.
Also, the command couldn’t find the host file without specifying the root directory with a “/” before “etc/hosts”.
Other than that, it worked great, thanks!
August 22nd, 2010 at 12:27 am
Constant fighting between the kids whenever they played games at miniclip.com until I did this.
However, I had to do write this after changing hosts:
sudo dscacheutil -flushcache
and also it only worked when I had “www.miniclip.com” not “miniclip.com” or “http://www.miniclip.com”
Weird!
October 30th, 2010 at 11:14 pm
I followed the second set of instructions. But it says that file/directory can’t be found. plz help :|
December 21st, 2010 at 6:23 pm
I just wanted to say that this tutorial was awesome and relatively easy to follow… Especially for someone with no programming background. A lot of the problems I was encountering were caused by my syntax. Even if you have a rogue ’space’ character between 2 other characters, it would throw the whole command off.
As Jeff said above, you need to make sure you’re adding the ‘/’ before “etc/hosts” so that it becomes “/etc/hosts”
Terminal is so finicky, if you enter a bash command a vast majority of the time it won’t work because there’s an error with your syntax. Hence why I could never be a programmer.
January 9th, 2011 at 6:40 pm
Thank you! I had to try twice because there is an extra quotation mark right before the — echo — line but it worked. thank. you. a million.
also, when you type etc/hosts, you have to type /etc/hosts otherwise it doesn’t recognize it and says there is no directory of that name or something of the like.
i hope other people see this comment so that it works for them! thanks again! i have been trying to find a way to block sites in safari forever.
January 22nd, 2011 at 11:06 pm
thefakegeek-
The second set of instructions worked for me, and I was able to block facebook, but how do I undo this if I want to allow the website to run again?
thanks
January 28th, 2011 at 4:37 pm
How do you unblock the website after?
May 17th, 2011 at 8:07 pm
Ok, I successfully blocked some addictive websites while studying for exams. Now I’d like to get it back…can you explain how to UNblock a website?
Thanks!
August 19th, 2011 at 6:08 pm
To get the websites back:
1. Open terminal
2. Type sudo pico /etc/hosts and press enter (if prompted for password type your password)
3. Scroll down to the line where the website is you want to remove e.g. 127.0.0.1 http://www.facebook.com
4. Delete the line
To Save the changes:
5. Hold the Ctrl key and press X
7. Press Y
7. Press the Enter key
August 24th, 2011 at 12:31 pm
I get to the very end but can not get anything to save….what are the steps to saving
September 24th, 2011 at 7:54 pm
Once you try to close the window it should prompt for you to save the file.
December 17th, 2011 at 2:09 am
Is this for PC or mac?
January 4th, 2012 at 5:49 pm
This is for Mac. PC’s also have a host file. Instructions on blocking websites on PCs can be found here: http://www.overclock.net/t/44143/how-to-use-the-hosts-file-to-block-websites-in-windows
July 28th, 2012 at 12:20 am
thanks it works..but how can i unblock those websites?thanks.:)
July 28th, 2012 at 12:25 am
thanks GAZ..
:)))