You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
26 KiB

  1. # DNS based ad/abuse domain blocking
  2. ## Description
  3. 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.
  4. ## Main Features
  5. * Support of the following fully pre-configured domain blocklist sources (free for private usage, for commercial use please check their individual licenses)
  6. | Source | Enabled | Size | Focus | Information |
  7. | :------------------ | :-----: | :--- | :--------------- | :-------------------------------------------------------------------------------- |
  8. | adaway | x | S | mobile | [Link](https://github.com/AdAway/adaway.github.io) |
  9. | adguard | x | L | general | [Link](https://adguard.com) |
  10. | anti_ad | | L | compilation | [Link](https://github.com/privacy-protection-tools/anti-AD/blob/master/README.md) |
  11. | andryou | | L | compilation | [Link](https://gitlab.com/andryou/block/-/blob/master/readme.md) |
  12. | anudeep | | M | compilation | [Link](https://github.com/anudeepND/blacklist) |
  13. | bitcoin | | S | mining | [Link](https://github.com/hoshsadiq/adblock-nocoin-list) |
  14. | disconnect | x | S | general | [Link](https://disconnect.me) |
  15. | dshield | | XL | general | [Link](https://dshield.org) |
  16. | energized_blugo | | XL | compilation | [Link](https://energized.pro) |
  17. | energized_blu | | XL | compilation | [Link](https://energized.pro) |
  18. | energized_porn | | XXL | compilation+porn | [Link](https://energized.pro) |
  19. | energized_ultimate | | XXL | compilation | [Link](https://energized.pro) |
  20. | energized_unified | | XXL | compilation | [Link](https://energized.pro) |
  21. | malwaredomains | | M | malware | [Link](https://malwaredomains.com) |
  22. | malwarelist | | S | malware | [Link](https://www.malwaredomainlist.com) |
  23. | notracking | | XL | tracking | [Link](https://github.com/notracking/hosts-blocklists) |
  24. | oisd_nl | | XXL | general | [Link](https://oisd.nl) |
  25. | openphish | | S | phishing | [Link](https://openphish.com) |
  26. | phishing_army | | S | phishing | [Link](https://phishing.army) |
  27. | reg_cn | | M | reg_china | [Link](https://easylist.to) |
  28. | reg_cz | | M | reg_czech+slovak | [Link](https://easylist.to) |
  29. | reg_de | | M | reg_germany | [Link](https://easylist.to) |
  30. | reg_es | | M | reg_espania | [Link](https://easylist.to) |
  31. | reg_fi | | S | reg_finland | [Link](https://github.com/finnish-easylist-addition) |
  32. | reg_fr | | S | reg_france | [Link](https://forums.lanik.us/viewforum.php?f=91) |
  33. | reg_id | | M | reg_indonesia | [Link](https://easylist.to) |
  34. | reg_kr | | M | reg_korea | [Link](https://list-kr.github.io) |
  35. | reg_nl | | M | reg_netherlands | [Link](https://easylist.to) |
  36. | reg_pl | | M | reg_poland | [Link](https://kadantiscam.netlify.com) |
  37. | reg_ro | | M | reg_romania | [Link](https://easylist.to) |
  38. | reg_ru | | M | reg_russia | [Link](https://easylist.to) |
  39. | reg_vn | | M | reg_vietnam | [Link](https://bigdargon.github.io/hostsVN) |
  40. | shallalist | | L | general | [Link](http://www.shallalist.de) |
  41. | shallalist_porn | | XXL | general+porn | [Link](http://www.shallalist.de) |
  42. | smarttv | | S | smarttv | [Link](https://github.com/Perflyst/PiHoleBlocklist) |
  43. | spam404 | | S | general | [Link](https://github.com/Dawsey21) |
  44. | stevenblack | | L | compilation | [Link](https://github.com/StevenBlack/hosts) |
  45. | stevenblack_porn | | L | compilation+porn | [Link](https://github.com/StevenBlack/hosts) |
  46. | stopforumspam | | S | spam | [Link](https://www.stopforumspam.com) |
  47. | sysctl | | M | general | [Link](http://sysctl.org/cameleon) |
  48. | utcapitole | | L | general | [Link](https://dsi.ut-capitole.fr/blacklists/index_en.php) |
  49. | utcapitole_porn | | XXL | general+porn | [Link](https://dsi.ut-capitole.fr/blacklists/index_en.php) |
  50. | wally3k | | S | compilation | [Link](https://firebog.net/about) |
  51. | whocares | | M | general | [Link](https://someonewhocares.org) |
  52. | winhelp | | S | general | [Link](http://winhelp2002.mvps.org) |
  53. | winspy | | S | win_telemetry | [Link](https://github.com/crazy-max/WindowsSpyBlocker) |
  54. | youtube | | M | youtube | [Link](https://github.com/kboghdady/youTube_ads_4_pi-hole) |
  55. | yoyo | x | S | general | [Link](http://pgl.yoyo.org/adservers) |
  56. * List of supported and fully pre-configured adblock sources, already active sources are pre-selected.
  57. <b><em>To avoid OOM errors, please do not select too many lists!</em></b>
  58. List size information with the respective domain ranges as follows:
  59. <b>S</b> (-10k), <b>M</b> (10k-30k) and <b>L</b> (30k-80k) should work for 128 MByte devices,
  60. <b>XL</b> (80k-200k) should work for 256-512 MByte devices,
  61. <b>XXL</b> (200k-) needs more RAM and Multicore support, e.g. x86 or raspberry devices.
  62. * Zero-conf like automatic installation & setup, usually no manual changes needed
  63. * Simple but yet powerful adblock engine: adblock does not use error prone external iptables rulesets, http pixel server instances and things like that
  64. * Supports five different DNS backend formats: dnsmasq, unbound, named (bind), kresd or raw (e.g. used by dnscrypt-proxy)
  65. * Supports four different SSL-enabled download utilities: uclient-fetch, wget, curl or aria2c
  66. * Supports SafeSearch for google, bing, duckduckgo, yandex, youtube and pixabay
  67. * Fast downloads & list processing as they are handled in parallel running background jobs with multicore support
  68. * Supports a wide range of router modes, even AP modes are supported
  69. * Full IPv4 and IPv6 support
  70. * 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
  71. * Provides a 'DNS File Reset', where the generated DNS blocklist file will be purged after DNS backend loading to save storage space
  72. * 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')
  73. * Overall duplicate removal in generated blocklist file 'adb_list.overall'
  74. * Additional local blacklist for manual overrides, located in '/etc/adblock/adblock.blacklist'
  75. * Additional local whitelist for manual overrides, located in '/etc/adblock/adblock.whitelist'
  76. * Quality checks during blocklist update to ensure a reliable DNS backend service
  77. * Minimal status & error logging to syslog, enable debug logging to receive more output
  78. * Procd based init system support ('start', 'stop', 'restart', 'reload', 'enable', 'disable', 'running', 'status', 'suspend', 'resume', 'query', 'report', 'list', 'timer')
  79. * Auto-Startup via procd network interface trigger or via classic time based startup
  80. * Suspend & Resume adblock temporarily without blocklist reloading
  81. * Provides comprehensive runtime information
  82. * Provides a detailed DNS Query Report with DNS related information about client requests, top (blocked) domains and more
  83. * Provides a powerful query function to quickly find blocked (sub-)domains, e.g. for whitelisting
  84. * Provides an easily configurable blocklist update scheduler called 'Refresh Timer'
  85. * 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
  86. * Includes an option to force DNS requests to the local resolver
  87. * Automatic blocklist backup & restore, these backups will be used in case of download errors and during startup
  88. * Send notification E-Mails in case of a processing error or if the overall domain count is &le; 0
  89. * Add new adblock sources on your own, see example below
  90. * Strong LuCI support, all relevant options are exposed to the web frontend
  91. ## Prerequisites
  92. * [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
  93. <b>Please note:</b> Older OpenWrt releases like 18.06.x or 17.01.x are _not_ supported!
  94. <b>Please note:</b> Devices with less than 128 MByte RAM are _not_ supported!
  95. * A usual setup with an enabled DNS backend at minimum - dump AP modes without a working DNS backend are _not_ supported
  96. * A download utility with SSL support: 'wget', 'uclient-fetch' with one of the 'libustream-*' ssl libraries, 'aria2c' or 'curl' is required
  97. * A certificate store such as 'ca-bundle' or 'ca-certificates', as adblock checks the validity of the SSL certificates of all download sites by default
  98. * Optional E-Mail notification support: for E-Mail notifications you need to install the additional 'msmtp' package
  99. * Optional DNS Query Report support: for DNS reporting you need to install the additional package 'tcpdump-mini' or 'tcpdump'
  100. * Optional support for gnu awk as alternative to the busybox default, install the additional package 'gawk'
  101. ## Installation & Usage
  102. * Update your local opkg repository (_opkg update_)
  103. * Install 'adblock' (_opkg install adblock_). The adblock service is enabled by default
  104. * Install the LuCI companion package 'luci-app-adblock' (_opkg install luci-app-adblock_)
  105. * 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
  106. * 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
  107. ## Adblock CLI Options
  108. * All important adblock functions are accessible via CLI as well.
  109. <b>Please note:</b> The 'status' command in 19.07.x and TurrisOS is only available via 'status_service'
  110. <pre><code>
  111. /etc/init.d/adblock
  112. Syntax: /etc/init.d/adblock [command]
  113. Available commands:
  114. start Start the service
  115. stop Stop the service
  116. restart Restart the service
  117. reload Reload configuration files (or restart if service does not implement reload)
  118. enable Enable service autostart
  119. disable Disable service autostart
  120. running Check if service is running
  121. status Service status
  122. suspend Suspend adblock processing
  123. resume Resume adblock processing
  124. query &lt;domain&gt; Query active blocklists and backups for a specific domain
  125. report [&lt;search&gt;] Print DNS statistics with an optional search parameter
  126. list [[&lt;add&gt;|&lt;remove&gt;] [source(s)]] List available adblock sources or add/remove them from config
  127. timer &lt;action&gt; &lt;hour&gt; [&lt;minute&gt;] [&lt;weekday&gt;] Set a cron based update interval
  128. </code></pre>
  129. ## Adblock Config Options
  130. * Usually the auto pre-configured adblock setup works quite well and no manual overrides are needed
  131. | Option | Default | Description/Valid Values |
  132. | :----------------- | :--------------------------------- | :--------------------------------------------------------------------------------------------- |
  133. | adb_enabled | 1, enabled | set to 0 to disable the adblock service |
  134. | adb_srcarc | -, /etc/adblock/adblock.sources.gz | full path to the used adblock source archive |
  135. | adb_srcfile | -, /tmp/adb_sources.json | full path to the used adblock source file, which has a higher precedence than the archive file |
  136. | adb_dns | -, auto-detected | 'dnsmasq', 'unbound', 'named', 'kresd' or 'raw' |
  137. | adb_fetchutil | -, auto-detected | 'uclient-fetch', 'wget', 'curl' or 'aria2c' |
  138. | adb_fetchparm | -, auto-detected | config options for the selected download utility, e.g. to disable the certificate check |
  139. | adb_trigger | -, not set | trigger network interface or 'not set' to use a time-based startup |
  140. | adb_triggerdelay | 2 | additional trigger delay in seconds before adblock processing begins |
  141. | adb_debug | 0, disabled | set to 1 to enable the debug output |
  142. | adb_nice | 0, standard prio. | valid nice level range 0-19 of the adblock processes |
  143. | adb_forcedns | 0, disabled | set to 1 to force DNS requests to the local resolver |
  144. | adb_maxqueue | 4 | size of the download queue to handle downloads & list processing in parallel |
  145. | adb_dnsdir | -, auto-detected | path for the generated blocklist file 'adb_list.overall' |
  146. | adb_dnstimeout | 10 | timeout in seconds to wait for a successful DNS backend restart |
  147. | adb_dnsinstance | 0, first instance | set to the relevant dns backend instance used by adblock (dnsmasq only) |
  148. | adb_dnsfilereset | 0, disabled | set to 1 to purge the final DNS blocklist file after DNS backend loading |
  149. | adb_dnsflush | 0, disabled | set to 1 to flush the DNS Cache before & after adblock processing |
  150. | adb_dnsinotify | -, not set | set to 1 to prevent adblock triggered restarts for DNS backends with autoload functions |
  151. | adb_dnsallow | -, not set | set to 1 to disable selective DNS whitelisting (RPZ pass through) |
  152. | adb_lookupdomain | example.com | external domain to check for a successful DNS backend restart or 'false' to disable this check |
  153. | adb_portlist | 53 853 5353 | space separated list of firewall ports which should be redirected locally |
  154. | adb_report | 0, disabled | set to 1 to enable the background tcpdump gathering process for reporting |
  155. | adb_reportdir | /tmp | path for DNS related report files |
  156. | adb_repiface | -, auto-detected | name of the reporting interface or 'any' used by tcpdump |
  157. | adb_replisten | 53 | space separated list of reporting port(s) used by tcpdump |
  158. | adb_repchunkcnt | 5 | report chunk count used by tcpdump |
  159. | adb_repchunksize | 1 | report chunk size used by tcpdump in MB |
  160. | adb_backup | 1, enabled | set to 0 to disable the backup function |
  161. | adb_backupdir | /tmp | path for adblock backups |
  162. | adb_tmpbase | /tmp | path for all adblock related runtime operations, e.g. downloading, sorting, merging etc. |
  163. | adb_safesearch | 0, disabled | set to 1 to enforce SafeSearch for google, bing, duckduckgo, yandex, youtube and pixabay |
  164. | adb_safesearchlist | -, not set | Limit SafeSearch to certain provider (see above) |
  165. | adb_safesearchmod | 0, disabled | set to 1 to enable moderate SafeSearch filters for youtube |
  166. | adb_mail | 0, disabled | set to 1 to enable notification E-Mails in case of a processing errors |
  167. | adb_mailreceiver | -, not set | receiver address for adblock notification E-Mails |
  168. | adb_mailsender | no-reply@adblock | sender address for adblock notification E-Mails |
  169. | adb_mailtopic | adblock&nbsp;notification | topic for adblock notification E-Mails |
  170. | adb_mailprofile | adb_notify | mail profile used in 'msmtp' for adblock notification E-Mails |
  171. | adb_mailcnt | 0 | minimum domain count to trigger E-Mail notifications |
  172. | adb_jail | 0 | set to 1 to enable the additional, restrictive 'adb_list.jail' creation |
  173. | adb_jaildir | /tmp | path for the generated jail list |
  174. ## Examples
  175. **Change the DNS backend to 'unbound':**
  176. No further configuration is needed, adblock deposits the final blocklist 'adb_list.overall' in '/var/lib/unbound' by default.
  177. **Change the DNS backend to 'named' (bind):**
  178. Adblock deposits the final blocklist 'adb_list.overall' in '/var/lib/bind'.
  179. To preserve the DNS cache after adblock processing you need to install & configure 'bind-rdnc'.
  180. To use the blocklist please modify '/etc/bind/named.conf':
  181. <pre><code>
  182. in the 'options' namespace add:
  183. response-policy { zone "rpz"; };
  184. and at the end of the file add:
  185. zone "rpz" {
  186. type master;
  187. file "/var/lib/bind/adb_list.overall";
  188. allow-query { none; };
  189. allow-transfer { none; };
  190. };
  191. </code></pre>
  192. **Change the DNS backend to 'kresd':**
  193. Adblock deposits the final blocklist 'adb_list.overall' in '/etc/kresd', no further configuration needed.
  194. <b>Please note:</b> The knot-resolver (kresd) is only available on Turris devices and does not support the SafeSearch functionality yet.
  195. **Enable E-Mail notification via 'msmtp':**
  196. To use the email notification you have to install & configure the package 'msmtp'.
  197. Modify the file '/etc/msmtprc':
  198. <pre><code>
  199. [...]
  200. defaults
  201. auth on
  202. tls on
  203. tls_certcheck off
  204. timeout 5
  205. syslog LOG_MAIL
  206. [...]
  207. account adb_notify
  208. host smtp.gmail.com
  209. port 587
  210. from dev.adblock@gmail.com
  211. user dev.adblock
  212. password xxx
  213. </code></pre>
  214. Finally enable E-Mail support and add a valid E-Mail receiver address in LuCI.
  215. **Service status output:**
  216. In LuCI you'll see the realtime status in the 'Runtime' section on the overview page.
  217. To get the status in the CLI, just call _/etc/init.d/adblock status_ or _/etc/init.d/adblock status\_service_ (in 19.07 and TurrisOS):
  218. <pre><code>
  219. /etc/init.d/adblock status_service
  220. ::: adblock runtime information
  221. + adblock_status : enabled
  222. + adblock_version : 4.0.2
  223. + blocked_domains : 52420
  224. + active_sources : adaway adguard andryou bitcoin disconnect winspy yoyo
  225. + dns_backend : kresd, /etc/kresd
  226. + run_utils : /usr/bin/curl, /bin/awk
  227. + run_ifaces : trigger: trm_wwan, report: br-lan
  228. + run_directories : base: /tmp, backup: /tmp, report: /tmp, jail: /tmp
  229. + run_flags : backup: 1, reset: 0, flush: 0, force: 1, search: 0, report: 1, mail: 0, jail: 0
  230. + last_run : start, 0m 17s, 496/198/218, 03.04.2020 08:55:14
  231. + system : CZ.NIC Turris Mox Board, TurrisOS 5.1.0 81264ebb51991aa2d17489852854e3b5ec3f514d
  232. </code></pre>
  233. The 'last\_run' line includes the used start type, the run duration, the memory footprint after DNS backend loading (total/free/available) and the date/time of the last run.
  234. **Edit, add new adblock sources:**
  235. The adblock blocklist sources are stored in an external, compressed JSON file '/etc/adblock/adblock.sources.gz'.
  236. This file is directly parsed in LuCI and accessible via CLI, just call _/etc/init.d/adblock list_:
  237. <pre><code>
  238. /etc/init.d/adblock list
  239. ::: Available adblock sources
  240. :::
  241. Name Enabled Size Focus Info URL
  242. ------------------------------------------------------------------
  243. + adaway x S mobile https://adaway.org
  244. + adguard x L general https://adguard.com
  245. + andryou x L compilation https://gitlab.com/andryou/block/-/blob/master/readme.md
  246. + bitcoin x S mining https://github.com/hoshsadiq/adblock-nocoin-list
  247. + disconnect x S general https://disconnect.me
  248. + dshield XL general https://www.dshield.org
  249. [...]
  250. + winhelp S general http://winhelp2002.mvps.org
  251. + winspy x S win_telemetry https://github.com/crazy-max/WindowsSpyBlocker
  252. + yoyo x S general https://pgl.yoyo.org
  253. </code></pre>
  254. To add new or edit existing sources extract the compressed JSON file _gunzip /etc/adblock/adblock.sources.gz_.
  255. A valid JSON source object contains the following required information, e.g.:
  256. <pre><code>
  257. [...]
  258. "adaway": {
  259. "url": "https://raw.githubusercontent.com/AdAway/adaway.github.io/master/hosts.txt",
  260. "rule": "/^127\\.0\\.0\\.1[[:space:]]+([[:alnum:]_-]+\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}",
  261. "size": "S",
  262. "focus": "mobile",
  263. "descurl": "https://github.com/AdAway/adaway.github.io"
  264. },
  265. [...]
  266. </code></pre>
  267. 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.
  268. <b>Please note:</b> if you're going to add new sources on your own, please make a copy of the default file and work with that copy further on, cause the default will be overwritten with every adblock update. To reference your copy set the option 'adb\_srcarc' which points by default to '/etc/adblock/adblock.sources.gz'
  269. <b>Please note:</b> when adblock starts, it looks for the uncompressed 'adb\_srcfile', only if this file is not found the archive 'adb\_srcarc' is unpacked once and then the uncompressed file is used
  270. ## Support
  271. 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>
  272. Have fun!
  273. Dirk