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 be modified to use the HOSTS file)

  • Compression-friendly - Can download and process zip- and 7zip-compressed files automatically. (Provided that unzip and p7zip are installed)

  • Non-interactive - Can be run as a periodic cronjob or systemd 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, using 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 - Enchances security by combating DNS cache poisoning.

  • Extensive choice of blocklists included - Allowing the user to choose how much or how little is blocked/redirected.


Optional dependencies for additional features

Unarchivers to use archive blocklists instead of plain text:

  • unzip (for zip archives)
  • p7zip (for 7z archives) must include either 7z or 7za executables!

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:


First download the archive here or with curl like so: curl -O ""

Unzip the archive, e.g. unzip

Arch Linux

cd hostsblock-master/pkg; makepkg -Acsir

Or use one of the AUR packages: hostsblock, hostsblock-git

For others

install -Dm755 /usr/sbin/hostsblock
install -Dm755 /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 really well, so please read through it before first use.


To use Hostsblock together with Dnsmasq, configure Dnsmasq as DNS caching daemon. Please refer to your distribution's manual. For ArchLinux read the following: Wiki section.


In the FINAL HOSTSFILE section, enable hostsfile="/etc/hosts.block.


    systemctl restart dnsmasq.service # For dnsmasq under systemd


Set addn-hosts= to addn-hosts=/etc/hosts.block


  • Why isn't it working with Chrome/Chromium?

    • Because they bypass the system's DNS settings and use their own. To force them to use the system's DNS settings, refer to this question.

News & Bugs


Hostsblock is licensed under GNU GPL