Blocking websites using /etc/hosts
September 12, 2007 5:48 PM   Subscribe

Why won't OSX let me block MeFi via the /etc/hosts file?

I'm trying to make one computer "work only" and eliminate web sites on which I waste a lot of time (MeFi being one of them). I have successfully blocked all the websites that I care to EXCEPT MetaFilter. I am running OSX 10.4.10 on a MacBook Core 2 Duo. The following is my /etc/hosts file:


127.0.0.1 localhost metafilter.com www.metafilter.com metatalk.metafilter.com
255.255.255.255 broadcasthost
::1 localhost


I have tried it with JUST metafilter.com, just www.metafilter.com, etc. with no luck. Rebooting, refreshing, clearing cache, etc. MeFi continues to load normally. Safari, Opera, Firefox have all produced the same results. This is driving me crazy!
posted by proj to Computers & Internet (7 answers total) 1 user marked this as a favorite
 
I'm not sure that's correct syntax for that file. Try using a separate line for each host. For instance:
127.0.0.1 metafilter.com
127.0.0.1 www.metafilter.com
etc.
posted by xil at 5:55 PM on September 12, 2007


Response by poster: The other websites in the file (which I omitted) are all on the same line as well. I tried with separate lines and it still didn't work.
posted by proj at 5:57 PM on September 12, 2007


Best answer: What application or tool are you using to edit the /etc/hosts file? Perhaps you're using something that's messing up the line ending characters?

Also: To get the changes to be noticed by the system, without rebooting, do this in Terminal:
sudo lookupd -flushcache
(If even a reboot doesn't make it work, I doubt this will help, but it's worth knowing...)
posted by xil at 6:00 PM on September 12, 2007 [1 favorite]


Response by poster: That did the trick! Thanks!
posted by proj at 6:02 PM on September 12, 2007


I'm guessing this is because the resolver is looking at dns first, rather than files. I actually don't know how to change that behavior, but google does.
posted by cactus at 6:04 PM on September 12, 2007


No, by default lookupd looks in its cache first, then /etc/hosts, then DNS. I didn't think the cache persisted across reboots, but anything's possible.

You can see this yourself:
lookupd -configuration
reports that "Host Configuration" has a LookupOrder of "Cache FF DNS NI DS". FF == "Flat file" == /etc/hosts.
posted by xil at 6:10 PM on September 12, 2007


Ah, my mistake. Thanks for the clarification.
posted by cactus at 6:42 PM on September 12, 2007


« Older Name for aluminum-coated styrofoam?   |   apple don't care. Newer »
This thread is closed to new comments.