A lot of people already use adblocker plugins within their desktop browsers, but what if you are using your (smart) phone, tablet, watch or any other (wlan) gadget!? Getting rid of annoying ads, trackers and other abuse sites (like facebook) is simple: block them with your router. When the DNS server on your router receives DNS requests, you will sort out queries that ask for the resource records of ad servers and return a simple 'NXDOMAIN'. This is nothing but **N**on-e**X**istent Internet or Intranet domain name, if domain name is unable to resolved using the DNS server, a condition called the 'NXDOMAIN' occurred.
## Main Features
* Support of the following domain blocklist sources (free for private usage, for commercial use please check their individual licenses):
* [adaway](https://adaway.org)
* Infrequent updates, approx. 400 entries (enabled by default)
* [adguard](https://adguard.com)
* Numerous updates on the same day, approx. 12.000 entries
* Daily updates, approx. 64.000 entries (a short description of all categories can be found [online](https://dsi.ut-capitole.fr/blacklists/index_en.php))
* Weekly updates, approx. 2.500 entries (enabled by default)
* Support of the following fully pre-configured domain blocklist sources (free for private usage, for commercial use please check their individual licenses)
| whocares | | M | general | [Link](https://someonewhocares.org) |
| winhelp | | S | general | [Link](http://winhelp2002.mvps.org) |
| winspy | | S | win_telemetry | [Link](https://github.com/crazy-max/WindowsSpyBlocker) |
| yoyo | x | S | general | [Link](http://pgl.yoyo.org/adservers) |
* List of supported and fully pre-configured adblock sources, already active sources are pre-selected.
<b><em>To avoid OOM errors, please do not select too many lists!</em></b>
List size recommendations as follows:
• <b>S</b> (-10k), <b>M</b> (10k-30k) and <b>L</b> (30k-80k) should work for 128 MByte devices,
• <b>XL</b> (80k-200k) should work for 256-512 MByte devices,
• <b>XXL</b> (200k-) needs more RAM and Multicore support, e.g. x86 or raspberry devices.
* Zero-conf like automatic installation & setup, usually no manual changes needed
* Simple but yet powerful adblock engine: adblock does not use error prone external iptables rulesets, http pixel server instances and things like that
* Support four different DNS backends: `dnsmasq`, `unbound`, `named` (bind) and `kresd`
* Support two different DNS blocking variants: `nxdomain` (default, supported by all backends), `null` (supported only by `dnsmasq`)
* Support six different download utilities: `uclient-fetch`, `wget`, `curl`, `aria2c`, `wget-nossl`, `busybox-wget`
* Fast downloads & list processing as they are handled in parallel running background jobs (see 'Download Queue')
* Provide `http only` mode without installed SSL library for all non-SSL blocklist sources
* Support a wide range of router modes, even AP modes are supported
* Supports five different DNS backend formats: dnsmasq, unbound, named (bind), kresd or raw (e.g. used by dnscrypt-proxy)
* Supports four different SSL-enabled download utilities: uclient-fetch, wget, curl or aria2c
* Supports SafeSearch for google, bing, duckduckgo, yandex, youtube and pixabay
* Fast downloads & list processing as they are handled in parallel running background jobs with multicore support
* Supports a wide range of router modes, even AP modes are supported
* Full IPv4 and IPv6 support
* Provide top level domain compression (`tld compression`), this feature removes thousands of needless host entries from the blocklist and lowers the memory footprint for the DNS backend
* Provide a 'DNS File Reset', where the final DNS blockfile will be purged after DNS backend loading to save storage space
* Blocklist source parsing by fast & flexible regex rulesets
* Overall duplicate removal in central blocklist `adb_list.overall`
* Additional blacklist for manual overrides, located by default in `/etc/adblock/adblock.blacklist` or in LuCI
* Additional whitelist for manual overrides, located by default in `/etc/adblock/adblock.whitelist` or in LuCI
* Provides top level domain compression ('tld compression'), this feature removes thousands of needless host entries from the blocklist and lowers the memory footprint for the DNS backend
* Provides a 'DNS File Reset', where the generated DNS blocklist file will be purged after DNS backend loading to save storage space
* Source parsing by fast & flexible regex rulesets, all rules and source information are placed in an external/compredd JSON file ('/etc/adblock/adblock.sources.gz')
* Overall duplicate removal in generated blocklist file 'adb_list.overall'
* Additional local blacklist for manual overrides, located in '/etc/adblock/adblock.blacklist'
* Additional local whitelist for manual overrides, located in '/etc/adblock/adblock.whitelist'
* Quality checks during blocklist update to ensure a reliable DNS backend service
* Minimal status & error logging to syslog, enable debug logging to receive more output
* procd based init system support (`start/stop/restart/reload/suspend/resume/query/status`)
* procd network interface trigger support or classic time based startup
* Keep the DNS cache intact after adblock processing (currently supported by unbound, named and kresd)
* Suspend & resume adblock actions temporarily without blocklist reloading
* Provide comprehensive runtime information via LuCI or via `status` init command
* Provide a detailed DNS Query Report with DNS related information about client requests, top (blocked) domains and more
* Provide a query function to quickly identify blocked (sub-)domains, e.g. for whitelisting. This function is also able to search in adblock backups and black-/whitelist, to get back the set of blocking lists sources for a certain domain
* Option to force DNS requests to the local resolver
* Procd based init system support ('start', 'stop', 'restart', 'reload', 'enable', 'disable', 'running', 'status', 'suspend', 'resume', 'query', 'report', 'list', 'timer')
* Auto-Startup via procd network interface trigger or via classic time based startup
* Suspend & Resume adblock temporarily without blocklist reloading
* Provides comprehensive runtime information
* Provides a detailed DNS Query Report with DNS related information about client requests, top (blocked) domains and more
* Provides a powerful query function to quickly find blocked (sub-)domains, e.g. for whitelisting
* Provides an easily configurable blocklist update scheduler called 'Refresh Timer'
* Includes an option to generate an additional, restrictive 'adb_list.jail' to block access to all domains except those listed in the whitelist file. You can use this restrictive blocklist manually e.g. for guest wifi or kidsafe configurations
* Includes an option to force DNS requests to the local resolver
* Automatic blocklist backup & restore, these backups will be used in case of download errors and during startup
* Send notification emails in case of a processing error or if the overall domain count is ≤ 0
* Send notification E-Mails in case of a processing error or if the overall domain count is ≤ 0
* Add new adblock sources on your own, see example below
* Strong LuCI support for all options
* Strong LuCI support, all relevant options are exposed to the web frontend
## Installation & Usage
### Prerequisites
* [OpenWrt](https://openwrt.org), tested with the stable release series (19.07) and with the latest snapshot
## Prerequisites
* [OpenWrt](https://openwrt.org), tested with the stable release series (19.07.x) and with the latest rolling snapshot releases. On turris devices it has been successfully tested with TurrisOS 5.1.x
<b>Please note:</b> Older OpenWrt releases like 18.06.x or 17.01.x are _not_ supported!
<b>Please note:</b> Devices with less than 128 MByte RAM are _not_ supported!
* A usual setup with an enabled DNS backend at minimum - dump AP modes without a working DNS backend are _not_ supported
* A download utility:
* To support all blocklist sources and in order to run the default configuration of `adblock`, a full version (with SSL support) of `wget`, `uclient-fetch` with one of the `libustream-*` SSL libraries, `aria2c` or `curl` is required
* The package used by default is probably `uclient-fetch` so in order to make `adblock` work with its default configuration it is needed to install one of the `libustream-*` SSL libraries. Example: `opkg install libustream-openssl`
* For limited devices with real memory constraints, adblock provides also a `http only` option and supports `wget-nossl` and `uclient-fetch` (without `libustream-ssl`) as well
* For more configuration options see examples below
* Email notification (optional): For email notification support you need the additional `msmtp` package
* DNS Query Report (optional): For this detailed report you need the additional package `tcpdump` or `tcpdump-mini`
### Installation of the core package
* Install `adblock` (`opkg install adblock`)
* A download utility with SSL support: 'wget', 'uclient-fetch' with one of the 'libustream-*' ssl libraries, 'aria2c' or 'curl' is required
* Optional E-Mail notification support: for E-Mail notifications you need to install the additional 'msmtp' package
* Optional DNS Query Report support: for DNS reporting you need to install the additional package 'tcpdump-mini' or 'tcpdump'
### LuCI adblock companion package
* It is strongly recommended to use the LuCI frontend to easily configure all powerful aspects of adblock
* The application is located in LuCI under the `Services` menu
### Configuration and controlling
* At minimum configure the appropriate DNS backend (`dnsmasq` by default), the download utility and enable the adblock service in `/etc/config/adblock`
* Control the adblock service manually with `/etc/init.d/adblock``start/stop/restart/reload/suspend/resume/status` or use the LuCI frontend
## Installation & Usage
* Update your local opkg repository (_opkg update_)
* Install 'adblock' (_opkg install adblock_). The adblock service is enabled by default
* Install the LuCI companion package 'luci-app-adblock' (_opkg install luci-app-adblock_)
* It's strongly recommended to use the LuCI frontend to easily configure all aspects of adblock, the application is located in LuCI under the 'Services' menu
* Update from a former adblock version is easy. During the update a backup is made of the old configuration '/etc/config/adblock-backup' and replaced by the new config - that's all
#### Tweaks
* **Runtime information:** The adblock status is available via `/etc/init.d/adblock status` (see example below)
* **Debug logging:** For script debugging please set the config option `adb\_debug` to `1` and check the runtime output with `logread -e "adblock"`
* **Storage expansion:** To process and store all blocklist sources at once it might be helpful to enlarge your temp directory with a swap partition => see [OpenWrt Wiki](https://openwrt.org/docs/guide-user/storage/fstab) for further details
* **coreutils sort:** To speedup adblock processing in particular with many enabled blocklist sources it is recommended to install the additional package `coreutils-sort`
* **Add white- / blacklist entries:** Add domain black- or whitelist entries to always-deny or -allow certain (sub) domains, by default both lists are empty and located in `/etc/adblock`. Please add one domain per line - ip addresses, wildcards & regex are _not_ allowed (see example below). You need to refresh your blocklists after changes to these static lists.
* **Download queue size:** For further download & list processing performance improvements you can raise the `adb\_maxqueue` value, e.g. `8` or `16` should be safe
* **Scheduled list updates:** For a scheduled call of the adblock service add an appropriate crontab entry (see example below)
* **Change startup behaviour:** By default the startup will be triggered by the `wan` procd interface trigger. Choose `none` to disable automatic startups, `timed` to use a classic timeout (default 30 sec.) or select another trigger interface
* **Suspend & resume adblocking:** To quickly switch the adblock service `on` or `off`, simply use `/etc/init.d/adblock [suspend|resume]`
* **Domain query:** To query the active blocklist for a certain domain, please use the LuCI frontend or run _/etc/init.d/adblock query `<DOMAIN>`_ (see example below)
* **Add new list sources:** You can add new blocklist sources on your own via uci config, all you need is a source url and an awk one-liner (see example below)
## Adblock CLI Options
* All important adblock functions are accessible via CLI as well.
Please note: The 'status' command in 19.07.x and TurrisOS is only available via 'status_service'
<pre><code>
/etc/init.d/adblock
Syntax: /etc/init.d/adblock [command]
#### Further adblock config options
* Usually the pre-configured adblock setup works quite well and no manual overrides are needed
* The following options apply to the `global` config section:
* `adb_enabled` => Main switch to enable/disable adblock service (default: `0`, disabled)
* `adb_dns` => Select the DNS backend for your environment: `dnsmasq`, `unbound`, `named` or `kresd` (default: `dnsmasq`)
* `adb_dnsvariant` => Select the blocking variant: `nxdomain` (default, supported by all backends), `null (IPv4)` and `null (IPv4/IPv6)` both options are only supported by `dnsmasq`
* `adb_fetchutil` => Name of the used download utility: `uclient-fetch`, `wget`, `curl`, `aria2c`, `wget-nossl` or `busybox` (default: `uclient-fetch`)
* `adb_fetchparm` => Special config options for the download utility (default: not set)
* `adb_trigger` => Set the startup trigger to a certain interface, to `timed` or to `none` (default: `wan`)
* The following options apply to the `extra` config section:
* `adb_nice` => Set the nice level of the adblock process and all sub-processes (int/default: `0`, standard priority)
* `adb_forcedns` => Force DNS requests to local resolver (bool/default: `0`, disabled)
* `adb_maxqueue` => Size of the download queue to handle downloads & list processing in parallel (int/default: `8`)
* `adb_dnsfilereset` => The final DNS blockfile will be purged after DNS backend loading to save storage space (bool/default: `false`, disabled)
* `adb_report` => Enable the background tcpdump gathering process to provide a detailed DNS Query Report (bool/default: `0`, disabled)
* `adb_repdir` => Target directory for DNS related report files generated by tcpdump (default: `/tmp`)
* `adb_backupdir` => Target directory for adblock backups (default: `/tmp`)
* `adb_mail` => Send notification emails in case of a processing errors or if the overall domain count is ≤ 0 (bool/default: `0`, disabled)
* `adb_mreceiver` => Receiver address for adblock notification emails (default: not set)
* The following options could be added via "Additional Field" in LuCI and apply to the `extra` config section as well:
* `adb_dnsdir` => Target directory for the generated blocklist `adb_list.overall` (default: not set, use DNS backend default)
* `adb_dnsinstance` => set the relevant adblock enabled dnsmasq instance (int/default: '0', first dnsmasq instance)
* `adb_blacklist` => Full path to the static blacklist file (default: `/etc/adblock/adblock.blacklist`)
* `adb_whitelist` => Full path to the static whitelist file (default: `/etc/adblock/adblock.whitelist`)
* `adb_triggerdelay` => Additional trigger delay in seconds before adblock processing begins (int/default: `2`)
* `adb_maxtld` => Disable the tld compression, if the number of blocked domains is greater than this value (int/default: `100000`)
* `adb_portlist` => Space separated list of fw ports which should be redirected locally (default: `53 853 5353`)
* `adb_dnsinotify` => Disable adblock triggered restarts and the 'DNS File Reset' for DNS backends with autoload features (bool/default: `false`, disabled)
* `adb_dnsflush` => Flush DNS cache after adblock processing, i.e. enable the old restart behavior (bool/default: `0`, disabled)
* `adb_repiface` => Reporting interface used by tcpdump, set to `any` for multiple interfaces (default: `br-lan`)
* `adb_replisten` => Space separated list of reporting port(s) used by tcpdump (default: `53`)
* `adb_repchunkcnt` => Report chunk count used by tcpdump (default: `5`)
* `adb_repchunksize` => Report chunk size used by tcpdump in MB (int/default: `1`)
reload Reload configuration files (or restart if service does not implement reload)
enable Enable service autostart
disable Disable service autostart
running Check if service is running
status Service status
suspend Suspend adblock processing
resume Resume adblock processing
query <domain> Query active blocklists and backups for a specific domain
report [<search>] Print DNS statistics with an optional search parameter
list [[<add>|<remove>] [source(s)]] List available adblock sources or add/remove them from config
timer <action><hour> [<minute>] [<weekday>] Set a cron based update interval
</code></pre>
#### Examples
**Change default DNS backend to `unbound`:**
## Adblock Config Options
* Usually the auto pre-configured adblock setup works quite well and no manual overrides are needed
Adblock deposits the final blocklist `adb_list.overall` in `/var/lib/unbound` where unbound can find them in its jail, no further configuration needed.
To preserve the DNS cache after adblock processing you need to install `unbound-control`.
+ system : CZ.NIC Turris Mox Board, TurrisOS 5.1.0 81264ebb51991aa2d17489852854e3b5ec3f514d
</code></pre>
The 'last\_run' line includes the used start type, the duration of the last run, the memory footprint after DNS backend loading (total/free/available) and the date/time of the last run.
This entry removes the following (sub)domains from the blocklist:
maps.here.com
here.com
This entry does not remove:
where.com
www.adwhere.com
```
**Query the active blocklist, the backups and black-/whitelist for a certain (sub-)domain, e.g. for whitelisting:**
The query function checks against the submitted (sub-)domain and recurses automatically to the upper top level domain. For every (sub-)domain it returns the first ten relevant results.
```
/etc/init.d/adblock query google.com
:::
::: results for domain 'google.com' in active blocklist
**Edit, add new adblock sources:**
The adblock blocklist sources are stored in an external, compressed JSON file '/etc/adblock/adblock.sources.gz'.
This file is directly parsed in LuCI and accessible via CLI, just call _/etc/init.d/adblock list_:
<pre><code>
/etc/init.d/adblock list
::: Available adblock sources
:::
+ adservice.google.com
+ adservice.google.com.au
+ adservice.google.com.vn
+ adservices.google.com
+ analytics.google.com
+ googleadapis.l.google.com
+ pagead.l.google.com
+ partnerad.l.google.com
+ ssl-google-analytics.l.google.com
+ video-stats.video.google.com
+ [...]
:::
::: results for domain 'google.com' in backups and black-/whitelist
Adblock already supports an easylist source, called 'reg_ru'. To add the additional local easylist as a new source, copy the existing config source section and change only the source name, the url and the description - that's all!
+ andryou x L compilation https://gitlab.com/andryou/block/-/blob/master/readme.md
+ bitcoin x S mining https://github.com/hoshsadiq/adblock-nocoin-list
+ disconnect x S general https://disconnect.me
+ dshield XL general https://www.dshield.org
[...]
+ winhelp S general http://winhelp2002.mvps.org
+ winspy x S win_telemetry https://github.com/crazy-max/WindowsSpyBlocker
+ yoyo x S general https://pgl.yoyo.org
</code></pre>
2. A bit harder ...
To add a really new source with different domain/host format you have to write a suitable awk one-liner on your own, so basic awk skills are needed. As a starting point check the already existing awk rulesets `adb_src_rset` in the config file, probably you need only small changes for your individual list. Download the desired list and test your new awk string locally. The output result should be a sequential list with one domain/host per line - nothing more. If your awk one-liner works quite well, add a new source section to the adblock config file and test the new source.
To add new or edit existing sources extract the compressed JSON file _gunzip /etc/adblock/adblock.sources.gz_.
A valid JSON source object contains the following required information, e.g.:
Add an unique object name, make the required changes to 'url', 'rule', 'size' and 'descurl' and finally compress the changed JSON file _gzip /etc/adblock/adblock.sources.gz_ to use the new source object in adblock.
## Support
Please join the adblock discussion in this [forum thread](https://forum.openwrt.org/t/adblock-support-thread/507) or contact me by email <dev@brenken.org>
Please join the adblock discussion in this [forum thread](https://forum.openwrt.org/t/adblock-support-thread/507) or contact me by mail <dev@brenken.org>
option adb_src_desc 'huge blocklist archive subdivided in different categories, daily updates. Check http://www.shallalist.de/categories.html for more categories'
option adb_src_desc 'huge blocklist archive subdivided in different categories, daily updates. Check https://dsi.ut-capitole.fr/blacklists/index_en.php for more categories'