How to Block Access to Websites in Mac OS X

closePlease note: This post was published over a year ago, so please be aware that its content may not be quite so accurate anymore. Also, the format of the site has changed since it was published, so please excuse any formatting issues.

TerminalThe keyboard I use at work has some keys on it that are a bit tough to press. Being someone who types all day long as part of my job, this is somewhat annoying. Only slightly more annoying is what happens when I attempt to type in, but accidentally enter You can visit and see for yourself, but I suggest you take my word for it when I say the site resizes your browser.

I’m pretty particular about my browser window, its size, and its placement, so when a site resizes it, I get irritated. To make matters worse, I visit several times a day and about a third of the time I make the typo, which means my browser gets resized daily.

I’ve been putting up with this for a while, but after it happened again this morning, I decided I had put up with long enough. I blocked access to altogether, and in case you ever need to know how to block access to websites in OS X, I’ll tell you how I did it (like everyone else, I assume no responsibility if you break your computer).

To accomplish this, you’re going to need root access to the machine (which you have if you know the administrator password). Open the application called Terminal (it’s in the Utilities folder inside your Applications folder). You’re going to edit your ‘hosts’ file, and it’s always a good idea to back stuff up before you goof around with it. To do that, type in:

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

Press ‘enter’ and type in your password. Now you’re ready to edit the file. Type in:

sudo /usr/bin/pico /etc/hosts

When you press ‘enter,’ your ‘hosts’ file will open in a text editing program called pico. Use the arrow keys to move the caret to the end of the last line and hit ‘enter’ a couple of times to get to a new, blank line. Then type in:


Obviously, if you want to block a site other than, you would type that in instead. Once you’re finished adding sites you want to block, press ‘control’ and ‘x’ at the same time. Pico will ask if you want to save your changes, so press ‘y’ and then ‘enter.’

To test your work, clear your browser’s cache and try to visit (or whatever you typed in). Your browser should say that it can’t find the site. So what magic did you do to accomplish this? You told your computer to look for and at the IP address, which is the localhost IP address. In plain English, that means it’s looking for on your own computer ( always means “this computer”). Since obviously isn’t hosted on your machine, it doesn’t work (if your computer is set up to serve web pages, you’ll likely see that instead of an error message).

Pro Tip: Instead of using and having the site fail altogether, use the IP address of an actual website and have OS X automatically forward you to a useful site. Unfortunately, every IP address I can find for takes me to instead.

0 People like this. Be the first!


  1. This also works in Linux and Windows. For Windows, the hosts file is under %SystemRoot%\system32\drivers\etc\

    [My hosts file is 285KB; I have 10051 blocked addresses (thanks to Safer Networking Limited)]

  2. You can put more than one name on a line, thus setting up aliases. It’s convenient to put related entries together as aliases of each other, thus:

    If you use Firefox, you can probably find an extension that’ll automatically fix what you type, allowing you to actually turn all “.cm” into “.com”. I haven’t looked for one, but I bet one exists.

  3. Barry, you mean like URL Fixer? ^_^

    I also have a vague memory of a DNS (I think) solution, but nothing came up in the first few pages of a search. Hmm. :-/

  4. Maggie

    Thank you so much for posting this in the kind of detail a laymen can understand. I just broke up with somebody and I need a way to stop myself from indulging in the masochistic urge to read their blog. This is perfect.

  5. You’re welcome, Maggie. Glad I could help!

    If you’re looking for a new blog to read obsessively, my archives go back 8 years. There’s some interesting stuff in there.

  6. Cassie

    Ugh, I’m with Maggie!!

    But I can’t seem to make this work. When it comes time to type in my password, I am unable to enter any text. If I hit enter and then type it in, I get an error message. Help!!!

Leave a Reply