Hosts Adblock

Your rating: None Average: 4.9 (21 votes)

Ad blocking solution using the /etc/hosts file. Weekly auto-updated from MVPS .

This is a proven way of blocking ads, banners, 3rd party cookies, 3rd party page counters etc. by adding blocking rules to the /etc/hosts system file.

There is already another similar app - noADShosts - while my app is inspired by it, it shares no code and has some advantages.


  • The hosts file from MVPS is first sanitized (for only comments and rerouting to, which should minimize security risks even if the site itself is compromised.
  • The adblock lists gets updated weekly (using a systemd cron job). You can adjust this period by editing /etc/systemd/system/update_hosts_adblock.timer , but these changes may be overturned if this package gets updated.
  • You can manually update the list whenever you want to by running update_hosts_adblock as root (devel-su).
  • Your own rules are preserved and you can still edit them and add new ones by editing /etc/hosts.editable file. Mind that for your changes to come to effect, you need to re-run update_hosts_adblock .
  • There should be no risks in deleting this package when you want to stop using it. It just recreates your /etc/hosts file using the /etc/hosts.editable (backup) file during uninstallation.
  • If you ever (accidentaly or on purpose) delete your /etc/hosts file, run update_hosts_adblock command as root and the file will be recreated with your default Jolla config. Therefore should not be worried about replacing other packages dealing with /etc/hosts.
  • If there is no internet connection on the next weekly update, your hosts file will simply stay as it is and wait for the next week.
  • Starting from version 0.3, it also supports the Android /system/etc/hosts file. From version 0.4 it also supports the /opt/alien/system/etc/hosts file. /system/etc/hosts.editable and /opt/alien/system/etc/hosts.editable allow custom rules for these hosts files.


  • It takes 0.5-1.5MB in the filesystem.
  • Every (weekly or manual) update fetches approximately 500KB, so be careful if you don't connect through WiFi - it may reduce your FUP limit on the mobile internet.


Even if I haven't run into any problems, there might be some, so use with caution (you have been warned).

Please tell me if you experience any problems.


If you like this solution, please consider a small donation:

Donate in EUR

Donate in USD

Application versions: 
File sailfishos-hosts-adblock-0.4-1.noarch.rpm5.51 KB13/03/2016 - 00:58
File sailfishos-hosts-adblock-0.3-1.noarch.rpm4.94 KB05/12/2015 - 14:26
File sailfishos-hosts-adblock-0.2-1.noarch.rpm4.4 KB05/12/2015 - 04:28

0.4 - Improved Android support. Various code improvements.

0.3 - More robust check for existing MVPS hosts. Android support.

0.2 - Added fetched hosts sanitization

0.1 - First package for SailfishOS


nick8325's picture

The package is currently not working - it does not modify the hosts file. This is because update_hosts_adblock checks that that the downloaded MVPS hosts file is at least 12000 lines long, but it is currently a little shorter. To fix it, edit the file /usr/bin/update_hosts_adblock and change the line:


to e.g.:


P.S. thanks for the super-useful package!

claustn's picture

It would be nice to have the possibility to temporarily disable the blocked hosts. Otherwise certain websites does not work at all.

zwieberl's picture

No sure if this is still maintained or not, but I get windows-lineendings in the new hosts-file, which makes it not work.

After doing

tr -d '\r' < /etc/hosts  > /tmp/hosts
mv /tmp/hosts /etc/hosts

to it, it works.


EDIT: Probably even easier is to switch to


which contains MVPS plus a lot of other lists

olf's picture

Thank you for this proper ad-blocker for SailfishOS, as this was very much needed. And the (new) feature of patching the Android hosts file makes using AdAway (from F-Droid) superfluous.
But obviously Hosts Adblock 0.4.1 blocks fewer advertising servers than AdAway, so you may enhance Hosts Adblock by consulting more extensive hosts list(s).
AdAway uses per default:
# This file is generated from the following sources:
From these sources AdAway creates /opt/alien/system/etc/hosts (example uploaded to, truncated from 2 MB to 53 KB by cut&paste-ing), merging these lists while removing duplicate entries.
So using one of Steven Black's compiled host name lists (as recommended below) is far less hassle to implement (also thanks to your tidy /usr/bin/update_hosts_adblock shell script), they are collections of the hosts lists AdAway uses and a little more, work very well (also for Android in-app ads etc.) and look reasonable and trustworthy.
As AdAway is unable to patch /etc/hosts and /system/etc/hosts running as root under AlienDalvik, your Hosts Adblock for SailfishOS comes very handy. :)

olf's picture

So I did:

[nemo@Sailfish ~]$ diff /usr/bin/update_hosts_adblock.orig /usr/bin/update_hosts_adblock
> # Selecting the "unified" hosts blocking list from <> (picking the basic list, as the extended ones tend to block too eagerly):
< echo "# Autogenerated by the sailfishos-hosts-adblock app from" >> $1
> echo "# Autogenerated by the sailfishos-hosts-adblock app with the \"unified\" hosts blocking list from <>" >> $1

Working nicely. :)
See update_hosts_adblock.patched@pastebin for the full file.

incognito's picture

Thanks nodevel, quite an useful script.

A suggestion for future updates - MVPS hosts file is not enough, it won't weed out quite some number of Android in-app ads and a lot of more local-oriented ads in general. I suggest using StevenBlack's Unified hosts file (includes MVPS, adaway and couple of other lists) instead. It is frequently updated and readily available from: .

The best part? Since it includes the MVPS list the 'check_mvps' function will pass so no changes are needed, apart from replacing the value of REMOTE_HOSTS to point to the aforementioned list (and in the interim anybody can do it by editing the /usr/bin/update_hosts_adblock script ).

(Not sure if my last comment went through, repeating it just in case)

Brooks's picture

So far, great app, works perfect on jolla c.
Many thanks

delilat's picture

I agree, a Whitelist would be awesome.

objectifnul's picture

Instructions in /etc/hosts.editable seem to be ignored. BTW I don't know if I'm supposed to use «» or «» (I've tried both without success)

If I append hosts.editable instructions to hosts it's ok (until next automatic update of course).


EDIT: My bad, I didn't check carefully enough. What actually happens is this: instructions in /etc/hosts.editable are incorporated into /etc/hosts every time an automatic or forced update is performed. That's just perfect.

nodevel's picture

Thanks for noticing, I should have made it clearer in the description. The info is now added.

giskard's picture

How can I do to whitelist an host? If I comment its row in /etc/hosts, it will be overwritten by the next update.

nodevel's picture


sorry, I did not notice your comment.

You currently cannot whitelist a host. I'll try looking into it for a next update, but no promises. Thanks for the idea, though.

MooCrumpus's picture

How to uninstall it?

nodevel's picture

Like any other app, nothing special :)

Either find the package in Warehouse and uninstall, or uninstall it via terminal (zypper/pkcon).

objectifnul's picture

Nice. "editing /systemd/system/update_hosts_adblock.timer" should be "editing /etc/systemd/system/update_hosts_adblock.timer"

Note: conflicts with noADShosts. If already installed, remove it first, according to BloodyFoxy's instructions

nodevel's picture

Thanks, typo corrected.

Regarding the conflict with noADShosts, starting from version 0.3, it should be even more robust in recognizing either missing or already fetched (from MVPS) /etc/hosts file and recreate it from scratch. So you should be fine with simply removing the noADShosts package.

I even hope the package management would resolve the conflicts/dependencies automatically, but it looks like you need to remove the conflicting package manually, if installing through Warehouse.

olf's picture

You should be able to trigger uninstalling No Ads Hosts by explicitly stating that Hosts Adblock conflicts with the noadshosts RPM in your Spec file (other RPMs from Warehouse are successfully doing that).

eson's picture

Thanks a lot! I've been doing this manually for "years", and updating is so easy to forget.