How to quickly switch hosts file (Linux)
November 22, 2006 7:27 AM   Subscribe

How to quickly switch between hosts files on Linux?

I use a hosts file to block ad and spyware sites. Occasionally I'll have a problem viewing a site and I want to check if it's due to an entry in my hosts file. I could just temporarily overwrite /etc/hosts with a default hosts file, but that requires restarting firefox, losing all my open tabs and any sessions I have running. Is there some extension/desktop widget that I could use to quickly toggle the non-localhost entries in my hosts file off and on?
posted by primer_dimer to Computers & Internet (6 answers total)
 
Best answer: The solution is to use the Adblock extension instead of the hosts file. Ad blocking has come a long way, baby! Get Adblock and the Filterset G updater. Ads disappear, and if you have any problems, you can whitelist a site or a page (which in their terminology, means ignore Adblock for this site or page and load all the crap that is linked from this site or page).
posted by jellicle at 7:44 AM on November 22, 2006 [1 favorite]


Well, you could make two files, hosts.small and hosts.large, and have the actual /etc/hosts be a symlink to one or the other. Then write two batch files:

#!/bin/sh

sudo ln -sf /etc/hosts.large /etc/hosts


Call that one usehosts.large, or something that you can remember.

#!/bin/sh

sudo ln -sf /etc/hosts.small /etc/hosts


And that one should be usehosts.small.

Then make both files executable:

chmod u+x usehosts.large usehosts.small

Add icons on your desktop or Start menu pointing to those two batch files. When you double-click one, it will ask you for your password, and then change /etc/hosts to point to whichever file you chose.

On preview: Adblock and filterset.g are really great. That would probably be a better way to handle it. But if you want to automate what you're already doing, see above.
posted by Malor at 7:47 AM on November 22, 2006


Oh, one more thing: before running either of those scripts, save your old /etc/hosts somewhere. You may want it back someday.
posted by Malor at 7:52 AM on November 22, 2006




Response by poster: Ahh, I see that Adblock really has come a long way. Last time I tried it there were no filtersets available; that makes all the difference.
posted by primer_dimer at 8:49 AM on November 22, 2006


You could also try using privoxy, which in its default configuration obscures certain browser information, blocks some cookies, removes popups and blocks ads.

The last time I tried using Adblock, it wasn't quite configurable enough, so I switched to using this as a local proxy. Judging from the responses above, things may have changed since then.

On the downside, whitelisting is slightly more involved (manually edit a config file), but it's trivial to disable the proxy if you want to quickly test.
posted by blender at 1:42 PM on November 22, 2006


« Older XML for formatting web documents   |   Need a good offense for a youth basketball team Newer »
This thread is closed to new comments.