Block Facebook using Host file

Discussion in 'Mac Basics and Help' started by wluprocks, Aug 20, 2012.

  1. macrumors newbie

    Mar 8, 2012
    I've had success blocking every other website that I am trying to block using my host file, but it does not seem to work for facebook. I have attached an image of my host file so you can see what I do. While attempting to block Facebook I have also searched for every url that facebook might use and put those in and after that did not work I only put in one line for facebook which was just ''. Every time I do this I also flush the cache through Terminal. In case it matters I have Lion.

    Also, interestingly as part of my test I attempted to block, but that did not work. Though I don't care to block, just facebook

    Attached Files:

  2. macrumors 65816

    Nov 26, 2007
    Austin, TX
    You might consider using a service like opendns to do this.
  3. macrumors 68030

    Sep 21, 2011
    I can't offer any answer to your question, but I have one of my own: what's the gain in blocking sites that way?
  4. macrumors 6502


    Apr 23, 2011
    apple is a liberal company, should block
  5. macrumors 6502a

    Stooby Mcdoobie

    Jun 26, 2012
    My only guess would be that he/she does not want his/her kids accessing the sites, but I am curious as well.
  6. macrumors 68020


    Feb 16, 2012
    They use websense at guantanamo bay.
  7. thread starter macrumors newbie

    Mar 8, 2012
    I'm a freelancer and I work out of my house and this helps me be more productive and not waste time online, blocking through Apple's controls really sucks because you have to approve EVERY website and cookie that comes through(you can't ONLY block a few sites) and other services like Selfcontrol you have to reimplement every day. This is an easy, free, and thoughtless way to get me to not waste time once I have it in place. Yes I know how to go through Terminal now, but its enough of a deter for me to be more productive and not easily escape to websites that are easy to waste time on.

    ScoobyMcDoo and charlieegan3 I will look into those.
  8. macrumors 603

    Aug 9, 2009
    Some of the lines in your "hosts" file look wrong. All the ones where you have "http://blah.blah" should be simple hostnames, not URLs. A URL contains a hostname component, but a URL is not a hostname.

    Also see this article:

    Found by googling mac os hosts file. It's on the first page of results.
  9. wluprocks, Aug 20, 2012
    Last edited: Aug 20, 2012

    thread starter macrumors newbie

    Mar 8, 2012
    Tried that guys technique and it didn't work at first, then I added 'www.' in front of every hostname and it worked for everything except for facebook...this article surfaced yesterday, but its about Windows:

    Could mac be doing the same thing?

    I've also attached the new code, much less lines of code so thats nice, but still facebook works even with their host attached

    Edit: Actually strangely the new technique works for but not

    Attached Files:

  10. macrumors 68030


    Oct 31, 2007
    Well you're doing something wrong, because the hosts file shouldn't have any http:// or www in it. If you block, it will block all subdomains of Facebook including the www subdomain. I know you said in some cases that the blocks didn't work without www, but my point is that they should. All of the addresses you're blocking in your hosts file are blocked just fine without www on my machine.

    Perhaps it's an issue with ownership/permissions on your hosts file. What do you get when you ls -la /etc/hosts? Mine shows
    -rw-r--r--  1 root  wheel  949 Aug 20 18:52 /etc/hosts
    BTW, the article stating that custom host entries have to be entered at the beginning of the file in Lion is just false. All my custom rules have been added at the end on my machines and work just fine.
  11. thread starter macrumors newbie

    Mar 8, 2012
    When I first tried to do this whole thing I had permissions problems and had to repair them. I entered in the code you gave me and it says -rw-r--r--@ 1 root wheel 661 Aug 20 18:27 /etc/hosts

    Also, in case anyone is wondering the only experience I have with any form of coding is HTML/CSS and thats just enough to design/maintain my own website...

    Do you think this could be a Lion thing?
  12. macrumors 6502

    Jun 22, 2012
    Seriously, you want to block access to National Public Radio and The Daily Show? Well, there's still the New York Times and ten million more sources of liberal thought.
  13. macrumors 68030


    Oct 31, 2007
    No I don't think it has anything to do with Lion. I run Lion and have not experienced your issues. I hope someone else may have a suggestion.
  14. thread starter macrumors newbie

    Mar 8, 2012
    Thanks for trying to help.

    As for users commenting on/noticing my website preferences these are ones that I tend to waste the most time on and I would think anyone who is not a liberal should be happy to help me block those sites ;)
  15. Vizin, Aug 20, 2012
    Last edited: Feb 28, 2013

    macrumors 6502a

    Jun 30, 2007
  16. macrumors 603

    Aug 9, 2009
    Well, if technical means fail, there's always self-restraint. And that's not just the whiskey talking.
  17. thread starter macrumors newbie

    Mar 8, 2012
    If only that wasn't wishful thinking...I'm pretty much addicted to the internet
  18. macrumors 68000

    Apr 25, 2012
    Do you have a router for your internet access? How about implementing the controls on that to block the sites you don't want to be able to browse?
  19. thread starter macrumors newbie

    Mar 8, 2012
    Thats a good idea except that I work out of my home (I still allow myself to browse those sites during my leisure time) and have a roommate. Thanks for the suggestion though!
  20. macrumors member

    Jun 10, 2009
    Virginia, USA
    Check out OpenDNS

    You could use their domain blocking feature (requires registration and log-in) on your "work" computer by setting their DNS servers to OpenDNS, and using your ISP's DNS servers on the other computers in the house like always.
  21. macrumors 68000

    Apr 25, 2012
    Some of the more advanced routers may allow for granular application of the block rule, based on either MAC address or IP address (set your work machine as static if this is the case). Mine might, it's a Netgear WNDR3700 (I think). You should then also be able to set the policy to only apply during certain hours of the day. It'd be in the "Parental Controls" section of most routers, by which logic (if the firmware is any good), it should be able to block on a system-by-system basis rather than on a network-wide basis.

    DD-WRT may also be available for your router and might allow this level of blocking (but research before jumping into that route).

    Part of what I'm getting at is this; if you're researching (and struggling) the way to do it using the hosts file, look into other means. There's more than one way to solve this problem.
  22. thread starter macrumors newbie

    Mar 8, 2012
    Thanks for the advice. I will talk to my roommate who has access to the router through his computer about that. I think what made me keep trying with this was the fact that facebook was the ONLY site that did not work for me. If half of them worked or it only blocked one I would have searched for a different method right away.


    Thanks, I will look into that.
  23. macrumors 6502

    Feb 25, 2003
    Tempe, AZ

    hey i dont know if you're still having this issue but I am trying to accomplish the exact goal (being that, im trying to block time-wasting websites in my home office)... obviously there are always around this stuff but usually my brain kicks in when i start to go to /etc/hosts and i keep myself from removing the listings.

    ANYWAY, i too had the same problem with facebook still being accessible despite entries being in the hosts file. after doing some research online, i found that you have to block a whole bunch of related sites, as I believe there is some kind of redirect going on through their login server which is bypassing the hosts block.

    Try putting ALL of these entries in your hosts file, reboot and see if you still can access facebook:
  24. macrumors 68000

    Apr 25, 2012
    As an addendum to my previous suggestion.

    In playing with my router settings, I found that it will block sites based on keywords in the address. So, on my router if I just enter 'facebook' in the block list it will block ALL links with 'Facebook' in them. Now, this is a Netgear WNDR3700 with the Netgear firmware, others will differ.

Share This Page