Ad-blocking via /etc/hosts
(general explainer - my motivation)
After installation the script runs immediately, and then updates every week (configurable).
By default medium protection is used, provided by one of firebog’s meta lists, checked against false positives.
You can add as many sources as you want - they’ll be combined and de-duplicated to create the ultimate ad-blocking hosts file.
3 formats are supported, all are URLs to:
- a list of URLs to hosts blocklists (
metalists) - uBlock’s uassets repo (all will be stripped of extra information HOSTS cannot deal with) (
uassets) - actual hosts blocklists (many lists contain extra info or formatting, but the script will extract the domains only) (
listurls)
Each variable can contain several URLs, separated by newlines.
If you want stricter or less strict blocking, copy
/usr/share/doc/hosts-block/cfg.sh to /home/defaultuser/.config/hosts-block/
and edit it to your liking.
The file is sourced by the ash shell script, i.e. it follows shell syntax.
When the edited config file is saved a forced run is triggered automatically.
You can force-regenerate the hosts file manually with devel-su systemctl start hosts-block-forced.service or devel-su hosts-block forced.
The script sends various graphical notifications when something important
happens (good or bad).
“Modifications to this file normally take effect immediately, except in cases where the file is cached by applications”
(source). Since this is the case for the SFOS browser you will be prompted to restart it if required.
White-/Blacklisting
You can whitelist sites by creating
/home/defaultuser/.config/hosts-block/whitelist.txt - the format is much like hosts
itself but without the numerical IP address, so just the [sub.]domain.tld, one per line.
Same for blacklist.txt/blacklisting.
Both can also be achieved via two “Open with…” .desktop files that will show up in a context menu for links, but unfortunately
not in the browser itself as that would require a Share plugin (TODO).
Please keep in mind that the www. subdomain has to be specified explicitely, if so desired.
In other words, for most domains you’ll probably want 2 lines:
domain.tld
www.domain.tld
There is no way to add wildcards for all subdomains to hosts.
If one of the black/whitelist files is edited (manually or via .desktop entry), an offline (not forced) run is triggered automatically.
Before installing the package
There is nothing to do if you haven’t customized /etc/hosts. But if you want to use its content as the head of the new hosts file,
move/copy it to /etc/hosts.head before installing.
In any case, rpm will archive the existing /etc/hosts as /home/hosts*, on initial installation only.
If /etc/hosts.head does not exist, the script uses a default hosts.head (see repo) that covers both standard SFOS and AAS entries.
Either file becomes the “head” (i.e. the first few lines) of your new hostsfile.
It is, however, not a good idea to put to-be-blocked domains in /etc/hosts.head. Please use the blacklist feature for that (if you think
these domains haven’t been covered by one of the available blocklists already).
If you uninstall hosts-block /etc/hosts.head (or the repo default) will become your regular hosts file again.
Other apps writing to /etc/hosts?
You should not have other software installed that modifies hosts. System software won’t do this anyhow - the file is static
by definition (which does not mean that one isn’t allowed to modify it).
Nevertheless, upon first installation rpm will archive /etc/hosts to /home/hosts*tar.gz but will not restore it upon uninstallation.
Source
Framagit.org
Notabug.org


Systemctl )


