Skip navigation
This discussion is archived

hosts file

2694 Views 10 Replies Latest reply: Feb 18, 2008 11:10 PM by Tim Semic RSS
Tim Semic Level 1 Level 1 (120 points)
Currently Being Moderated
Feb 17, 2008 10:34 AM
I added an entry to the /etc/hosts file, setting a domain to 127.0.0.1 in order to block a domain. However the edit did not seem to have an effect.

What gives?


os = Tiger

Safari is bombing my console log with:
Unsafe JavaScript attempt to access frame with URL
Mac OS X (10.4.11)
  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Feb 17, 2008 1:08 PM (in response to Tim Semic)
    What did you edit the file with? You need to use a plain text editor that uses Unix line endings (vim, pico, BBEdit, TextWrangler, etc). You can also use the NetInfo Manager to add entries.
    G4 Digital Audio 1.4GHz, Mac OS X (10.4.11), G4 mini 1.4GHz, G3 MiniTower 500MHz (OS9)
  • Gnarlodious Level 4 Level 4 (3,220 points)
    Currently Being Moderated
    Feb 17, 2008 1:27 PM (in response to Tim Semic)
    You may need to reboot for the changes to take effect. It's happened to me. Another possibility is to flush the DNS cache. I actually have this alias in my profile that opens the hosts file and flushes the cache:

    alias hosts='sudo dscacheutil -flushcache;sudo nano /private/etc/hosts'
    2.4 MBP, Mac OS X (10.5.1)
  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Feb 17, 2008 2:30 PM (in response to Tim Semic)
    Not sure how verbose Safari is, you might try looking at the Activity window to see if you get the JavaScript errors in there also.

    To change the lookup order (see http://www.macwrite.com/criticalmass/mac-os-x-hosts-regrouped-pf.php - this is an older article, but still works for Tiger):

    [1] From the Terminal, check the current configuration
    lookupd -configuration

    [2] If the 'Host Configuration' does not have DNS following FF and NI, then change the configuration file:
    cd /etc
    sudo mkdir lookupd (make a new /etc/lookupd/ if it doesn't already exist))
    cd lookupd

    ls (check for files, just in case the directory already existed)
    cp hosts hosts.original (save the original, if needed)

    sudo echo LookupOrder Cache NI FF DNS DS > hosts (make a new host configuration lookup order)

    [3] Restart for any changes to take effect
    G4 Digital Audio 1.4GHz, Mac OS X (10.4.11), G4 mini 1.4GHz, G3 MiniTower 500MHz (OS9)
  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Feb 17, 2008 9:27 PM (in response to Tim Semic)
    I use the hosts file from this site, with the personal webserver configured to show me when something is getting blocked. I realize that some sites depend on ad revenue, but the hosts file usually doesn't block ads that are set in the page source, mostly those that are passed on to some ad server somewhere. If it isn't closely related to what I'm looking at, I am not interested in it anyway.

    If the site just has some non-standard (or just crappy) JavaScript, the hosts file probably won't help any. I don't think Safari can block individual JavaScripts, but maybe FIreFox has a plugin along those lines.
    G4 Digital Audio 1.4GHz, Mac OS X (10.4.11), G4 mini 1.4GHz, G3 MiniTower 500MHz (OS9)
  • Gnarlodious Level 4 Level 4 (3,220 points)
    Currently Being Moderated
    Feb 18, 2008 6:48 AM (in response to Tim Semic)
  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Feb 18, 2008 4:09 PM (in response to Tim Semic)
    Here is what I use:

    Setting up the webserver, if desired (see http://macmerc.com/sections.php?op=viewarticle&artid=83 ):

    [1] Edit the text file at /etc/httpd/httpd.conf (save the original somewhere)
    - look for the line "#ErrorDocument 404 /missing.html"
    - remove the comment character "#" and save the new file

    [2] Add the file missing.html to /Library/Webserver/Documents/
    - this can be anything, such as a blank HTML document
    - for feedback, use something like <i><strike>  ad blocked via hosts  </strike></i> or a small graphic

    [3] Turn on your personal webserver (System Preferences > Sharing)
    - note that this will also allow others to access your /Users/username/Sites folder if your router forwards to it.
    G4 Digital Audio 1.4GHz, Mac OS X (10.4.11), G4 mini 1.4GHz, G3 MiniTower 500MHz (OS9)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.