Second Host file to block internet garbage

This is how I add a second host file to my systems to block internet Garbage to localhost so my browser never reaches the garbage sites. As an added bonus, I get DNS caching in the process with dnsmasq.

I like to keep /etc/host limited to important things and not to cluttered. I also want to keep the file I use for blocking easy to update. The first thing I do is pull the host file from a site like http://www.mvps.org/winhelp2002/hosts.txt and put it in /etc as /etc/hostblock and run dos2unix on it. I have found other sources for the hostblock host file, and all I have used preform well in blocking most the ad-ware, site tracking and shock sites.

The next step is to install dnsmasq. Once its installed edit /etc/dnsmasq.conf and change addn-hosts and cache-size

addn-hosts=/etc/hostsblock

cache-size=1000

addn-hosts adds the second host file to dnsmqsq and cache-size sets the max number of records dnsmqsq will cache.

Once that’s done, restart dnsmasq. Now that dnsmasq is running you need to tell the system to use it. This can be done with network manager or by editing /etc/resolv.conf. A quick google search on DNS caching should show you how to do that with your OS distribution.

To test that DNS caching is working type “dig” in the command line. You should see “SERVER: 127.0.0.1#53(127.0.0.1)” towards the bottom of the output. You can also test by typing “dig nathanboyce.com” twice in a row. Query time should be 0 msec the second time.

To test the host blocking run something like this

dig @127.0.0.1 $(grep -v \# /etc/hostsblock  |tail -1 |awk ‘{print $2}’) +short

It should output 127.0.0.1.  If it does, you’re done. Now you can relax ans know that you are blocking some of the internet garbage.

 

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*