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.

182 lines
11 KiB

  1. # adblock script for openwrt
  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 the local ip address of your router and the internal web server delivers a transparent pixel instead.
  4. ## Main Features
  5. * support of the following domain blocklist sources (free for private usage, for commercial use please check their individual licenses):
  6. * [adaway](https://adaway.org)
  7. * => infrequent updates, approx. 400 entries (enabled by default)
  8. * [blacklist]()
  9. * => static local blacklist, located by default in '/etc/adblock/adblock.blacklist'
  10. * [disconnect](https://disconnect.me)
  11. * => numerous updates on the same day, approx. 6.500 entries (enabled by default)
  12. * [dshield](http://dshield.org)
  13. * => daily updates, approx. 4.500 entries
  14. * [feodotracker](https://feodotracker.abuse.ch)
  15. * => daily updates, approx. 0-10 entries
  16. * [malwaredomains](http://malwaredomains.com)
  17. * => daily updates, approx. 16.000 entries
  18. * [malwaredomainlist](http://www.malwaredomainlist.com)
  19. * => daily updates, approx. 1.500 entries
  20. * [openphish](https://openphish.com)
  21. * => numerous updates on the same day, approx. 1.800 entries
  22. * [palevo tracker](https://palevotracker.abuse.ch)
  23. * => daily updates, approx. 15 entries
  24. * [ransomware tracker](https://ransomwaretracker.abuse.ch)
  25. * => daily updates, approx. 150 entries
  26. * [rolist/easylist](https://easylist-downloads.adblockplus.org/rolist+easylist.txt)
  27. * => weekly updates, approx. 600 entries
  28. * [ruadlist/easylist](https://code.google.com/p/ruadlist)
  29. * => weekly updates, approx. 2.000 entries
  30. * [shallalist](http://www.shallalist.de) (categories "adv" "costtraps" "spyware" "tracker" "warez" enabled by default)
  31. * => daily updates, approx. 32.000 entries (a short description of all shallalist categories can be found [online](http://www.shallalist.de/categories.html))
  32. * [spam404](http://www.spam404.com)
  33. * => infrequent updates, approx. 5.000 entries
  34. * [sysctl/cameleon](http://sysctl.org/cameleon)
  35. * => weekly updates, approx. 21.000 entries
  36. * [whocares](http://someonewhocares.org)
  37. * => weekly updates, approx. 12.000 entries
  38. * [winhelp](http://winhelp2002.mvps.org)
  39. * => infrequent updates, approx. 15.000 entries
  40. * [winspy](https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/hostsBlockWindowsSpy.txt)
  41. * => infrequent updates, approx. 120 entries
  42. * [yoyo](http://pgl.yoyo.org/adservers)
  43. * => weekly updates, approx. 2.500 entries (enabled by default)
  44. * [zeus tracker](https://zeustracker.abuse.ch)
  45. * => daily updates, approx. 440 entries
  46. * zero-conf like automatic installation & setup, usually no manual changes needed (i.e. ip address, network devices etc.)
  47. * supports a wide range of router modes, as long as the firewall and the DNS server are enabled
  48. * full IPv4 and IPv6 support
  49. * each blocklist source will be updated and processed separately
  50. * timestamp check to download and process only updated adblock list sources
  51. * overall duplicate removal in separate adblock lists (will be automatically disabled on low memory systems)
  52. * adblock source list parsing by fast & flexible regex rulesets
  53. * additional whitelist for manual overrides, located by default in /etc/adblock/adblock.whitelist
  54. * quality checks during & after update of adblock lists to ensure a reliable dnsmasq service
  55. * basic adblock statistics via iptables packet counters
  56. * list states, (overall) list counts & last update time will be stored in uci config
  57. * status & error logging to stdout and syslog
  58. * use a dynamic uhttpd instance as an adblock pixel server
  59. * use dynamic iptables rulesets for adblock related redirects/rejects
  60. * openwrt init system support (start/stop/restart/reload)
  61. * hotplug support, the adblock start will be triggered by wan 'ifup' event
  62. * optional: adblock list backup/restore (disabled by default)
  63. * optional: add new adblock sources via uci config (see example below)
  64. ## Prerequisites
  65. * [openwrt](https://openwrt.org), tested with latest stable release (Chaos Calmer) and with current trunk (Designated Driver)
  66. * usual openwrt setup with enabled 'iptables', 'dnsmasq' and 'uhttpd' - dump AP modes are _not_ supported!
  67. * additional required software packages:
  68. * wget
  69. * optional: 'kmod-ipt-nat6' for IPv6 support
  70. * the above dependencies and requirements will be checked during package installation & script runtime
  71. ## Designated Driver Installation & Usage
  72. * install 'adblock' (_opkg install adblock_)
  73. * adblock starts automatically during boot/wan-ifup event, check _logread -e "adblock"_ for adblock related information
  74. * optional: start/restart/stop the adblock service manually with _/etc/init.d/adblock_
  75. * optional: enable/disable your required adblock list sources in _/etc/config/adblock_ - 'adaway', 'disconnect' and 'yoyo' are enabled by default
  76. * optional: maintain the adblock service in luci under 'System => Startup'
  77. ## LuCI adblock companion package
  78. * for easy management of the various blocklist sources and adblock options there is also a nice & efficient LuCI frontend available
  79. * install 'luci-app-adblock' (_opkg install luci-app-adblock_)
  80. * the application is located in LuCI under 'Services' menu
  81. * _Thanks to Hannu Nyman for this great adblock LuCI frontend!_
  82. ## Chaos Calmer installation notes
  83. * 'adblock' and 'luci-app-adblock' are _not_ available as .ipk packages in the Chaos Calmer download repository
  84. * download both packages from a development snapshot package directory:
  85. * for 'adblock' look [here](https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/packages/)
  86. * for 'luci-app-adblock' look [here](https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/luci/)
  87. * manually transfer the packages to your routers temp directory (with tools like _sshfs_ or _winscp_)
  88. * install the packages with _opkg install <...>_ as described above
  89. ## Tweaks
  90. * to process & store all blocklist sources at once it might helpful to enlarge your temp directory with a swap partition => see [openwrt wiki](https://wiki.openwrt.org/doc/uci/fstab) for further details
  91. * add domain white- or blacklist entries to always-allow or -deny certain (sub) domains, by default both lists are located in _/etc/adblock_. Please add one domain per line - ip addresses, wildcards & regex are _not_ allowed (see example below)
  92. * enable the backup/restore feature, to restore automatically the latest stable backup of your adblock lists in case of any (partial) processing error (i.e. a single blocklist source is down). Please use an (external) solid partition and _not_ your volatile router temp directory for this
  93. * for a scheduled call of the adblock service via _/etc/init.d/adblock start_ add an appropriate crontab entry (see example below)
  94. * in case of any script runtime errors, you should enable script debugging: for this please change the 'DEBUG' variable in the header of _/usr/bin/adblock-update.sh_ from '0' to '1' and start this script afterwards (without any parameter)
  95. * you could 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)
  96. ## Further adblock config options
  97. * usually the adblock autodetection works quite well and no manual config overrides are needed, all options apply to the 'global' config section:
  98. * adb\_enabled => main switch to enable/disable adblock service (default: '1', enabled)
  99. * adb\_cfgversion => config version string (do not change!) - adblock will check this entry during startup
  100. * adb\_lanif => name of the logical lan interface (default: 'lan')
  101. * adb\_nullport => port of the adblock uhttpd instance (default: '65535')
  102. * adb\_nullipv4 => IPv4 blackhole ip address (default: '192.0.2.1')
  103. * adb\_nullipv6 => IPv6 blackhole ip address (default: '::ffff:c000:0201')
  104. * adb\_forcedns => redirect all DNS queries to local dnsmasq resolver (default: '1', enabled)
  105. ## Examples
  106. **example cronjob for a regular update of the block lists:**
  107. <pre><code>
  108. # configuration found in /etc/crontabs/root
  109. # start adblock script once a day at 6 a.m.
  110. #
  111. 0 06 * * * /etc/init.d/adblock start
  112. </code></pre>
  113. **example blacklist entry (/etc/adblock/adblock.blacklist):**
  114. <pre><code>
  115. ads.example.com
  116. </code></pre>
  117. This rule blocks:
  118. http://ads.example.com/foo.gif
  119. http://server1.ads.example.com/foo.gif
  120. https://ads.example.com:8000/
  121. This rule doesn't block:
  122. http://ads.example.com.ua/foo.gif
  123. http://example.com/
  124. **example whitelist entry (/etc/adblock/adblock.whitelist):**
  125. <pre><code>
  126. analytics.com
  127. </code></pre>
  128. This rule removes _all_ domains from the blocklists with this string in it, i.e.:
  129. google-analytics.com
  130. ssl.google-analytics.com
  131. api.gameanalytics.com
  132. photos.daily-deals.analoganalytics.com
  133. adblockanalytics.com
  134. **example to add [rolist+easylist](https://easylist-downloads.adblockplus.org/rolist+easylist.txt) as a new source:**
  135. <pre><code>
  136. add a new source section in adblock config, take an existing easylist source as a template and change only the source name, the url and the description
  137. config source 'ruadlist'
  138. option enabled '0'
  139. option adb_src 'https://easylist-downloads.adblockplus.org/ruadlist+easylist.txt'
  140. option adb_src_rset '{FS=\"[|^]\"} \$0 ~/^\|\|([A-Za-z0-9_-]+\.){1,}[A-Za-z]+\^$/{print tolower(\$3)}'
  141. option adb_src_desc 'focus on russian ad related domains plus generic easylist additions, weekly updates, approx. 2.000 entries'
  142. config source 'rolist'
  143. option enabled '0'
  144. option adb_src 'https://easylist-downloads.adblockplus.org/rolist+easylist.txt'
  145. option adb_src_rset '{FS=\"[|^]\"} \$0 ~/^\|\|([A-Za-z0-9_-]+\.){1,}[A-Za-z]+\^$/{print tolower(\$3)}'
  146. option adb_src_desc 'focus on romanian ad related domains plus generic easylist additions, weekly updates, approx. 600 entries'
  147. </code></pre>
  148. ## Background
  149. This adblock package is a dns/dnsmasq based adblock solution for openwrt.
  150. Queries to ad/abuse domains are never forwarded and always replied with a local IP address which may be IPv4 or IPv6.
  151. For that purpose adblock uses an ip address from the private 'TEST-NET-1' subnet (192.0.2.1 / ::ffff:c000:0201) by default.
  152. Furthermore all ad/abuse queries will be filtered by ip(6)tables and redirected to internal adblock pixel server (in PREROUTING chain) or rejected (in FORWARD or OUTPUT chain).
  153. All iptables and uhttpd related adblock additions are non-destructive, no hard-coded changes in 'firewall.user', 'uhttpd' config or any other openwrt related config files. There is _no_ adblock background daemon running, the (scheduled) start of the adblock service keeps only the adblock lists up-to-date.
  154. ## Support
  155. Please join the adblock discussion in this [openwrt forum thread](https://forum.openwrt.org/viewtopic.php?id=59803) or contact me by mail <openwrt@brenken.org>
  156. ## Removal
  157. * stop all adblock related services with _/etc/init.d/adblock stop_
  158. * optional: remove the adblock package (_opkg remove adblock_)
  159. Have fun!
  160. Dirk