Changing etc/hosts to ban website - permissions issue.

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

  1. model500 macrumors newbie

    Jul 20, 2008
    Hello I am trying to ban (too distracting!) from my mac at work by adding:

    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.
  2. ihabime macrumors 6502

    Jan 12, 2005
    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


    Oct 2, 2006
    The Land of Hope and Glory
    Open Terminal.

    Type cd /etc

    Type sudo nano hosts

    Type your password

    Edit File

    Hit Ctrl + O to save

    Hit Ctrl + X to quit


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

    Jul 20, 2008
    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 (tab)
  5. Shadow macrumors 68000


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

    Nov 14, 2007
    Try banning the IP address:

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

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


    Mar 11, 2008
    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

    Jan 5, 2006
    Redondo Beach, California
    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

    Jan 12, 2005
    That should work. I added "" 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


    Mar 11, 2008
    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: localhost

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

    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


    Jun 6, 2003
    Solon, OH
    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:

    killall -HUP lookupd
  12. ihabime macrumors 6502

    Jan 12, 2005
    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