HOW TO: Use the Hosts File on Linux to Block Ads, Tracking, Malware Domains and Annoyances


Welcome to the internet, it’s full of advertisers trying to sell you stuff you don’t need, trackers trying to steal and sell your data and malicious content waiting to hijack your device.

There are a few steps you can take to minimise these threats. Like taking advantage of the built in hosts file on your computer and a browser ad-blocker like uBlock Origin .

On macOS you can use GasMask which wasn’t updated in ages, but it still works. However, it still can’t deal with HTTPS sources. On Linux, a great option is hBlock.

hBlock is a 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.

1. Install hBlock:

curl -o /tmp/hblock '' \
  && echo 'd711ae3b0c6affce4237e32856d1b0e6fcff1e84523e5c8bbb25e79b4074cfe2  /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


1.1 If you’re using Arch/Manjaro hBlock is available in AUR


2. Run hblock -h to see the script arguments and how can you modify hBlock


3. Backup your original hosts file in /etc/hosts just in case. hBlock will modify the original file.

4. Execute the script with hblock


5.  The following commands will schedule a daily update of the hosts file:

curl -o '/tmp/hblock.#1' '{service,timer}' \
  && echo '70964235a03152d4bc68096a0b99cc59e3f77595b99330f8c55dcca79d7164ff  /tmp/hblock.service' | shasum -c \
  && echo '79ecc28c13b2489400bd5ddc0ee61ddaf6c3225acb1d54b5cb4026f822ae60e8  /tmp/hblock.timer' | shasum -c \
  && sudo mv /tmp/hblock.{service,timer} /etc/systemd/system/ \
  && sudo chown root:root /etc/systemd/system/hblock.{service,timer} \
  && sudo chmod 644 /etc/systemd/system/hblock.{service,timer} \
  && sudo systemctl daemon-reload \
  && sudo systemctl enable hblock.timer \
  && sudo systemctl start hblock.timer


Fore more info check out the official project on GitHub. This is a great directory of filter and host lists.



We don't think that using an adblocker = piracy. That's simply not true. We use and recommend uBlock Origin.

However, as a small non-corporate website, we would appreciate it if you'd consider whitelisting FSM in your adblock of choice.

Alternatively, consider donating using the options below....

Monero (XMR) 43GnqUNJrTi9QyL7kEH8vM8pgWGCE6bjv1FSRipeNMM4TTeNnUVsRBb6MfMpQYxtLE7ReonxVVSXz2rFCEdW5H11LC3x73b
Bitcoin (BTC) 1Hfuq77gKKFJeNcq4EP4dQK3yDRWrFEwJR
Bitcoin Cash (BCH) qzmdm6e6q5wf2p6sxz2mst7cenz60newwc5m4e9js8
Ether (ETH) 0x5f02869278C24A6579d3820f52AD15936D6F9d69
More content?  
Ads Blocker Image Powered by Code Help Pro

Congrats on using an adblocker. We mean it.

Please support us by disabling your AdBlocker or whitelist us.

Thank you! ❤️