How to quickly switch hosts file (Linux)
November 22, 2006 7:27 AM
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?
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?
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:
Call that one usehosts.large, or something that you can remember.
And that one should be usehosts.small.
Then make both files executable:
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
#!/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
posted by Malor at 7:52 AM on November 22, 2006
Stop using the damn hosts file to block ads, it was not designed for that and there are much better ways to block things.
posted by Rhomboid at 7:58 AM on November 22, 2006
posted by Rhomboid at 7:58 AM on November 22, 2006
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
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
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
This thread is closed to new comments.
posted by jellicle at 7:44 AM on November 22, 2006