Improve your security and privacy by blocking ads, tracking and malware domains.
Clone or download
Latest commit c1d4be9 Nov 1, 2018

Build Website License

Improve your security and privacy by blocking ads, tracking and malware domains.

Table of contents

What is this for?

This POSIX-compliant shell script, designed for Unix-like systems, gets a list of domains that serve ads, tracking scripts and malware from multiple sources and creates a hosts file (alternative formats are also supported) that prevents your system from connecting to them.

Is it safe to use?

Absolutely, this script selects only the domain names for each source, so if a domain name is redirected to a rogue server your system will not be affected. In the worst scenario you can lose access to a legitimate domain name due a false positive, but you can reverse it by adding that domain to the whitelist.

Nightly builds

I provide nightly builds of the hosts file and other formats, including installers for Windows (batch file) and Android (flashable zip).



curl -o /tmp/hblock '' \
  && echo '457b90dddf3882f0c3f84c43fedf899144f481802015ef1f93057af1acb0e153  /tmp/hblock' | shasum -c \
  && sudo mv /tmp/hblock /usr/local/bin/hblock \
  && sudo chown root:root /usr/local/bin/hblock \
  && sudo chmod 755 /usr/local/bin/hblock

Note: you can use this Systemd timer to regularly update the hosts file for new additions.

Optionally, it is possible to use NPX to run hBlock without installation

npx hblock


Script arguments

You can also change the default behavior using these options:

Usage: hblock [options...]
 -O, --output <FILE>
        Output file location
        (default: /etc/hosts)
 -R, --redirection <REDIRECTION>
        Redirection for all entries in the blocklist
 -H, --header <HEADER>
        Content to be included at the beginning of the file
        (e.g. "$(cat header.txt)")
 -F, --footer <FOOTER>
        Content to be included at the end of the file
        (e.g. "$(cat footer.txt)")
 -T, --template <TEMPLATE>
        POSIX BREs replacement applied to each entry
        \1 = <DOMAIN>, \2 = <REDIRECTION>
        (default: \2 \1)
 -C, --comment <COMMENT>
        Character used for comments
        (default: #)
 -S, --sources <URLS>
        Sources to be used to generate the blocklist
        (whitespace separated URLs)
 -W, --whitelist <ENTRIES>
        Entries to be removed from the blocklist
        (whitespace separated POSIX BREs)
 -B, --blacklist <ENTRIES>
        Entries to be added to the blocklist
 -b, --backup [DIRECTORY]
        Make a time-stamped backup in <DIRECTORY>
        (default: output file directory)
 -l, --lenient
        Match all entries from sources, regardless of their IP
        (default:, or none)
 -i, --ignore-download-error
        Do not abort if a download error occurs
 -c, --color <auto|true|false>
        Colorize the output
        (default: auto)
 -q, --quiet
        Suppress non-error messages
 -v, --version
        Show version number and quit
 -h, --help
        Show this help and quit

Preserve content

This script replaces the hosts file of your system, if you want to preserve part of its content, you should wrap that content with the following structure:

# <custom>
# </custom>

Run preview



Name Primary Mirror URL URL
AdBlock NoCoin List URL URL
AdGuard - Simplified URL URL - Ad URL URL - Malvertising URL URL - Malware URL URL - Tracking URL URL
EasyList URL URL
EasyPrivacy URL URL
ETH Phishing Detect URL URL
FadeMind - add.2o7Net URL URL
FadeMind - add.Dead URL URL
FadeMind - add.Risk URL URL
FadeMind - add.Spam URL URL
KADhosts URL URL URL URL - Immortal domains URL URL - Just domains URL URL - Spammers URL URL
mitchellkrogza - Badd-Boyz-Hosts URL URL URL URL URL URL URL URL URL URL
ZeroDot1 - CoinBlockerLists URL URL URL URL


This script, by default, replaces the /etc/hosts file of your system. I am not responsible for any damage or loss, always make backups.


See the license file.