gaenserich / hostsblock

an ad- and malware-blocking script for Linux
https://github.com/gaenserich/hostsblock
225 stars 28 forks source link

What is the difference between hostsblock and adblock? #32

Closed pickfire closed 9 years ago

gaenserich commented 9 years ago

From a user's perspective:

  1. hostsblock is a bit less nuanced (it blocks entire domains, e.g. "ads.google.com", not specific html elements as adblock does, e.g. banner ads on distrowatch.com that are hosted on the same domain as the content). In practice: it will block slightly fewer things than adblock.
  2. hostsblock is system-wide (reasons below), effecting not only stand-alone browsers but also any app that uses the operating systems dns services (i.e. pretty much everything).
    • The two don't conflict with each other. In fact, I use both so that I get the added benefit of system-wide protection along with cookie protection in my browser. They do not seem to cause a change in performance.

For those with technical knowledge:

  1. hostsblock uses an operating system's HOSTS file, a table of static ip to domain name associations that the operating system uses to override dns lookups. Adblock works within just the specific browser engine.
  2. hostsblock hacks the HOSTS file to redirect a list of known malicious and advertising domains to the localhost, that is, to nowhere. Adblock is less of a hack, working within the browser to intercept lookups to targeted elements.
  3. hostsblock is a relatively simple script (in bash scripting language) that downloads several (user-selected) known lists of blocklists and compiles them together into a singular "meta-blocklist". Adblock does a similar thing with a series of user-selected rules lists.
pickfire commented 9 years ago

I use tor with polipo, why doesn't the /etc/hosts worked?

gaenserich commented 9 years ago

Unless I am mistaken, polipo and other local proxies bypass the /etc/hosts file. The obvious workaround is to add the following to the postprocess () { } variable in hostsblock.conf:

    postprocess () {
        grep -v " localhost$" /etc/hosts | awk '{print $2}' > /etc/polipo/forbidden
        killall -SIGUSR1 -- polipo
    }

(If you have anything else in postprocess () {}, make sure to put it before the line with awk) This will snag out all blocked domains from /etc/hosts (if that is the destination file you use) except for localhost (you definitely don't want to block that domain), strip out the 127.0.0.1 or 0.0.0.0, and dump out the results to /etc/polipo/forbidden, where polipo keeps its own blocklist. the killall line tells polipo to reload the /etc/polipo/forbidden file.

pickfire commented 9 years ago

Yeah, tor and polipo bypass /etc/hosts so you could just strip you the 127.0.0.1 and 0.0.0.0, but I don't think we should use awk as it removes the comments.

pickfire commented 9 years ago

31