Changing etc/hosts to ban website - permissions issue.

Discussion in 'macOS' started by model500, Jul 20, 2008.

  1. model500 macrumors newbie

    Joined:
    Jul 20, 2008
    #1
    Hello I am trying to ban www.facebook.com (too distracting!) from my mac at work by adding:

    127.0.0.1 facebook.com

    at the bottom of the text on the file /etc/hosts. I have already added read and write for everyone in Sharing and Permissions having clicked get info on this file. Despite having this in place I still can not save the changes I make to the file - even though it clearly says I have read and write permissions.

    I have been able to do this in my XP Boot Camp but it not in OS X. I am running 10.5.4 having upgraded it from Leopard.

    http://www.flickr.com/photos/28778651@N07/2685829942/
     
  2. ihabime macrumors 6502

    Joined:
    Jan 12, 2005
    #2
    That's because the whole directory is admin permissions, and textedit is running with your current user perms.

    you can use the Go menu in finder to get to /private/etc/ and drag the hosts file to the desktop, edit and save it back to the desktop in textedit, then drag it back to /private/etc/
    a dialog will come up asking if you want to overwrite the original and then another asking for your admin password.

    or you can open terminal, type "sudo pico /private/etc/hosts it'll ask for you admin password, then you can edit the file in pico, save by hitting control-o and exit by hitting ctrl-x.

    You may have to return the permissions to what they were before editing too, it's best not to alter the permissions in those directories.
     
  3. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #3
    Open Terminal.

    Type cd /etc

    Type sudo nano hosts

    Type your password

    Edit File

    Hit Ctrl + O to save

    Hit Ctrl + X to quit

    Done.

    Edit : bah didn't see the explanation above :p.
     
  4. model500 thread starter macrumors newbie

    Joined:
    Jul 20, 2008
    #4
    I have made the changes and they can be seen on the host file. However I still have access to the site from which I am trying to ban myself. Is there anything else I need to do exceot 127.0.0.1 (tab) www.facebook.com
     
  5. Shadow macrumors 68000

    Shadow

    Joined:
    Feb 17, 2006
    Location:
    Keele, United Kingdom
  6. pjrobertson macrumors 6502a

    Joined:
    Nov 14, 2007
    #6
    Try banning the IP address:
    69.63.178.11

    It might not be the same for you depending on your location so run

    ping facebook.com
    in terminal (press CTRL + C to stop)
    you may also need to try www.facebook.com
    for me it has an IP of 69.63.184.15
     
  7. macrem macrumors 65816

    macrem

    Joined:
    Mar 11, 2008
    #7
    Funny how each has his/her own method for editing the hosts file. Mine's: "sudo vi /etc/hosts".

    Alternatively, perhaps the OP could try blocking facebook using Parental Controls.
     
  8. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #8
    What is the search order or name resolution? Is it files then DNS or DNS then files? If it is looking at /etc/hosts last then it's not going to work. Take a look in /etc/resolv.conf
     
  9. ihabime macrumors 6502

    Joined:
    Jan 12, 2005
    #9
    That should work. I added "127.0.0.1 www.facebook.com" to mine and it started blocking it immediately.

    Did you correct the permissions on the hosts file? They should be system read & write, wheel read only and everyone read only.

    Also, if you're editing in textedit, make sure it didn't ad .txt as the file extension, it won't show unless you have show all file extensions set in finder prefs. Get info on the file and check under Name & Extension, uncheck Hide extension.
     
  10. macrem macrumors 65816

    macrem

    Joined:
    Mar 11, 2008
    #10
    Going the hosts file route would not have been my first choice for blocking URLs, but anyway there should already be this line for the loopback:

    127.0.0.1 localhost

    ...why not add to that line rather than creating a new one? E.g.:

    127.0.0.1 localhost www.facebook.com

    In any case, with the above method if you have a webserver running, facebook's URL should take you to your local webserver page.
     
  11. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #11
    Also, if you're using Tiger or Leopard, after you edit the hosts file, it's necessary to restart lookupd. This can be done from the Terminal:

    Code:
    killall -HUP lookupd
     
  12. ihabime macrumors 6502

    Joined:
    Jan 12, 2005
    #12
    nope you don't have to restart in tiger or leopard, I've been using hosts to block ads since 10.2, it used to be a lot more complex, but now it picks up changes as soon as you save.
     

Share This Page