An ad-blocking and malware-blocking script for Linux
Hostsblock
is a bash
script designed to take advantage of
/etc/hosts
file to provide system-wide blocking of
internet advertisements, malicious domains, trackers, and
other undesirable content.
To do so, it downloads a configurable set of blocklists and processes their
entries into a single /etc/hosts
file.
Hostsblock
also includes hostsblock-urlcheck
, a command-line utility that
allows you to block and unblock certain websites and any other domains
contained in that website.
-
System-wide blocking - All non-proxied connections use the HOSTS file (Proxied connections can adopt the HOSTS file)
-
Compressed-friendly - Can download and process compressed files automatically. (Currently only
zip
and7zip
are supported) -
Non-interactive - Can be run as a periodic
cronjob
orsystemd timer
without needing user interaction. -
Extensive configurability - Allows for custom black & white listing, redirection, post-processing scripting, etc.
-
Bandwith-efficient - Only downloads blocklists that have been changed, uses compression when available.
-
Resource-efficient - Only processes blocklists when changes are registered, uses minimal pipes.
-
High performance blocking - Only when using dns caching and pseudo-server daemons.
-
Redirection capability - Enchance security and combats DNS cache poisoning.
-
Extensive choice of blocklists included - It is up to the user to choose how much or how little is blocked/redirected.
Unarchivers to use archive blocklists instead of plain text:
A DNS caching daemon to help speed up DNS resolutions:
A pseudo-server that serves blank pages to remove boilerplate page and speed up page resolution on blocked domains:
Compressors to compress backup files and the annotation database:
cd pkg; makepkg -Acsir
Or use one of the AUR packages: hostsblock, hostsblock-git
install -Dm755 hostsblock.sh /usr/sbin/hostsblock
install -Dm755 hostsblock-urlcheck.sh /usr/sbin/hostsblock-urlcheck
install -Dm644 hostsblock.conf /etc/hostsblock/hostsblock.conf
install -Dm644 black.list /etc/hostsblock/black.list
install -Dm644 white.list /etc/hostsblock/white.list
install -Dm644 hosts.head /etc/hostsblock/hosts.head
Don't forget to enable and start the systemd timer with:
systemctl enable --now hostsblock.timer
Refer to the man pages for more info about hostsblock's usage. (Currently useless! see #19)
All the Hostsblock configuration is done in the hostsblock.conf
.
This file is commented realy god, please read through it before first use.
To use Hostsblock together with Dnsmasq configure Dnsmasq as DNS cashing daemon. Pleas refer to your Distributions manual. For Archlinux read the following Wiki section.
In the FINAL HOSTSFILE section enable hostsfile="/etc/hosts.block
.
In the POSTPROCESSING SUBROUTINE section enable:
postprocess(){
systemctl restart dnsmasq.service # For dnsmasq under systemd
}
Set addn-hosts=
to addn-hosts=/etc/hosts.block
-
Why isn't it working witch Chrome/Chromium?
- Because they bypass the systems DNS settings and use they're own. To force them to use the systems DNS settings refer to this superuser.com question.
Hostsblock is licensed under GNU GPL