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.

331 lines
15 KiB

  1. # Unbound Recursive DNS Server with UCI
  2. ## Unbound Description
  3. [Unbound](https://www.unbound.net/) is a validating, recursive, and caching DNS resolver. The C implementation of Unbound is developed and maintained by [NLnet Labs](https://www.nlnetlabs.nl/). It is based on ideas and algorithms taken from a java prototype developed by Verisign labs, Nominet, Kirei and ep.net. Unbound is designed as a set of modular components, so that also DNSSEC (secure DNS) validation and stub-resolvers (that do not run as a server, but are linked into an application) are easily possible.
  4. ## Package Overview
  5. Unbound may be useful on consumer grade embedded hardware. It is _intended_ to be a recursive resolver only. [NLnet Labs NSD](https://www.nlnetlabs.nl/projects/nsd/) is _intended_ for the authoritative task. This is different than [ISC Bind](https://www.isc.org/downloads/bind/) and its inclusive functions. Unbound configuration effort and memory consumption may be easier to control. A consumer could have their own recursive resolver with 8/64 MB router, and remove potential issues from forwarding resolvers outside of their control.
  6. This package builds on Unbounds capabilities with OpenWrt UCI. Not every Unbound option is in UCI, but rather, UCI simplifies the combination of related options. Unbounds native options are bundled and balanced within a smaller set of choices. Options include resources, DNSSEC, access control, and some TTL tweaking. The UCI also provides an escape option and works at the raw "unbound.conf" level.
  7. ## HOW TO Ad Blocking
  8. The UCI scripts will work with [net/adblock 2.3+](https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md), if it is installed and enabled. Its all detected and integrated automatically. In brief, the adblock scripts create distinct local-zone files that are simply included in the unbound conf file during UCI generation. If you don't want this, then disable adblock or reconfigure adblock to not send these files to Unbound.
  9. ## HOW TO Integrate with DHCP
  10. Some UCI options and scripts help Unbound to work with DHCP servers to load the local DNS. The examples provided here are serial dnsmasq-unbound, parallel dnsmasq-unbound, and unbound scripted with odhcpd.
  11. ### Serial dnsmasq
  12. In this case, dnsmasq is not changed *much* with respect to the default OpenWrt/LEDE configuration. Here dnsmasq is forced to use the local Unbound instance as the lone upstream DNS server, instead of your ISP. This may be the easiest implementation, but performance degradation can occur in high volume networks. dnsmasq and Unbound effectively have the same information in memory, and all transfers are double handled.
  13. **/etc/config/unbound**:
  14. ```
  15. config unbound
  16. option add_local_fqdn '0'
  17. option add_wan_fqdn '0'
  18. option dhcp_link 'none'
  19. # dnsmasq should not forward your domain to unbound, but if...
  20. option domain 'yourdomain'
  21. option domain_type 'refuse'
  22. option listen_port '1053'
  23. ...
  24. ```
  25. **/etc/config/dhcp**:
  26. ```
  27. config dnsmasq
  28. option domain 'yourdomain'
  29. option noresolv '1'
  30. option resolvfile '/tmp/resolv.conf.auto'
  31. option port '53'
  32. list server '127.0.0.1#1053'
  33. list server '::1#1053'
  34. ...
  35. ```
  36. ### Parallel dnsmasq
  37. In this case, Unbound serves your local network directly for all purposes. It will look over to dnsmasq for DHCP-DNS resolution. Unbound is generally accessible on port 53, and dnsmasq is only accessed at 127.0.0.1:1053 by Unbound. Although you can dig/drill/nslookup remotely with the proper directives.
  38. **/etc/config/unbound**:
  39. ```
  40. config unbound
  41. option dhcp_link 'dnsmasq'
  42. option listen_port '53'
  43. ...
  44. ```
  45. **/etc/config/dhcp**:
  46. ```
  47. config dnsmasq
  48. option domain 'yourdomain'
  49. option noresolv '1'
  50. option resolvfile '/tmp/resolv.conf.auto'
  51. option port '1053'
  52. ...
  53. config dhcp 'lan'
  54. # dnsmasq may not issue DNS option if not std. configuration
  55. list dhcp_option 'option:dns-server,0.0.0.0'
  56. ...
  57. ```
  58. ### Unbound and odhcpd
  59. You may ask, "can Unbound replace dnsmasq?" You can have DHCP-DNS records with Unbound and odhcpd only. The UCI scripts will allow Unbound to act like dnsmasq. When odhcpd configures each DHCP lease, it will call a script. The script provided with Unbound will read the lease file for DHCP-DNS records. The unbound-control application is required, because simply rewriting conf-files and restarting unbound is too much overhead.
  60. - Default OpenWrt has dnsmasq+odhcpd with `odhcpd-ipv6only` limited to DHCPv6.
  61. - If you use dnsmasq+odhcpd together, then use dnsmasq serial or parallel methods above.
  62. - You must install package `odhcpd` (full) to use odhcpd alone.
  63. - You must install package `unbound-control` to load and unload leases.
  64. - Remember to uninstall (or disable) dnsmasq when you won't use it.
  65. **/etc/config/unbound**:
  66. ```
  67. config unbound
  68. # name your router in DNS
  69. option add_local_fqdn '1'
  70. option add_wan_fqdn '1'
  71. option dhcp_link 'odhcpd'
  72. # add SLAAC inferred from DHCPv4
  73. option dhcp4_slaac6 '1'
  74. option domain 'lan'
  75. option domain_type 'static'
  76. option listen_port '53'
  77. option rebind_protection '1'
  78. # install unbound-control and set this
  79. option unbound_control '1'
  80. ...
  81. ```
  82. **/etc/config/dhcp**:
  83. ```
  84. config dhcp 'lan'
  85. option dhcpv4 'server'
  86. option dhcpv6 'server'
  87. option interface 'lan'
  88. option leasetime '12h'
  89. option ra 'server'
  90. option ra_management '1'
  91. # odhcpd should issue ULA [fd00::/8] by default
  92. ...
  93. config odhcpd 'odhcpd'
  94. option maindhcp '1'
  95. option leasefile '/var/lib/odhcpd/dhcp.leases'
  96. # this is where the magic happens
  97. option leasetrigger '/usr/lib/unbound/odhcpd.sh'
  98. ```
  99. ## HOW TO Manual Override
  100. Yes, there is a UCI to disable the rest of Unbound UCI. However, OpenWrt or LEDE are targeted at embedded machines with flash ROM. The initialization scripts do a few things to protect flash ROM.
  101. ### Completely Manual (almost)
  102. All of `/etc/unbound` (persistent, ROM) is copied to `/var/lib/unbound` (tmpfs, RAM). Edit your manual `/etc/unbound/unbound.conf` to reference this `/var/lib/unbound` location for included files. Note in preparation for a jail, `/var/lib/unbound` is `chown unbound`. Configure for security in`/etc/unbound/unbound.conf` with options `username:unbound` and `chroot:/var/lib/unbound`.
  103. Keep the DNSKEY updated with your choice of flash activity. `root.key` maintenance for DNSKEY RFC5011 would be hard on flash. Unbound natively updates frequently. It also creates and destroys working files in the process. In `/var/lib/unbound` this is no problem, but it would be gone at the next reboot. If you have DNSSEC (validator) active, then you should consider the age UCI option. Choose how many days to copy from `/var/lib/unbound/root.key` (tmpfs) to `/etc/unbound/root.key` (flash).
  104. **/etc/config/unbound**:
  105. ```
  106. config unbound
  107. option manual_conf '1'
  108. option root_age '9'
  109. # end
  110. ```
  111. ### Hybrid Manual/UCI
  112. You like the UCI. Yet, you need to add some difficult to standardize options, or just are not ready to make a UCI request yet. The files `/etc/unbound/unbound_srv.conf` and `/etc/unbound/unbound_ext.conf` will be copied to Unbounds chroot directory and included during auto generation.
  113. The file `unbound_srv.conf` will be added into the `server:` clause. The file `unbound_ext.conf` will be added to the end of all configuration. It is for extended `forward-zone:`, `stub-zone:`, `auth-zone:`, and `view:` clauses. You can also disable unbound-control in the UCI which only allows "localhost" connections unencrypted, and then add an encrypted remote `control:` clause.
  114. ## Complete List of UCI Options
  115. **/etc/config/unbound**:
  116. ```
  117. config unbound
  118. Currently only one instance is supported.
  119. option add_extra_dns '0'
  120. Level. Execute traditional DNS overrides found in `/etc/config/dhcp`.
  121. Optional so you may use other Unbound conf or redirect to NSD instance.
  122. 0 - Ignore `/etc/config/dhcp`
  123. 1 - Use only 'domain' clause (host records)
  124. 2 - Use 'domain', 'mxhost', and 'srvhost' clauses
  125. 3 - Use all of 'domain', 'mxhost', 'srvhost', and 'cname' clauses
  126. option add_local_fqdn '0'
  127. Level. This puts your routers host name in the LAN (local) DNS.
  128. Each level is more detailed and comprehensive.
  129. 0 - Disabled
  130. 1 - Host Name on only the primary address
  131. 2 - Host Name on all addresses found (except link)
  132. 3 - FQDN and host name on all addresses (except link)
  133. 4 - Above and interfaces named <iface>.<hostname>.<domain>
  134. option add_wan_fqdn '0'
  135. Level. Same as previous option only this applies to the WAN. WAN
  136. are inferred by a UCI `config dhcp` entry that contains the line
  137. option ignore '1'.
  138. option dns64 '0'
  139. Boolean. Enable DNS64 through Unbound in order to bridge networks
  140. that are IPV6 only and IPV4 only (see RFC6052).
  141. option dns64_prefix '64:ff9b::/96'
  142. IPV6 Prefix. The IPV6 prefix wrapped on the IPV4 address for DNS64.
  143. You should use RFC6052 "well known" address, unless you also
  144. redirect to a proxy or gateway for your NAT64.
  145. option dhcp_link 'none'
  146. Program Name. Link to one of the supported programs we have scripts
  147. for. You may also need to install a trigger script in the DHCP
  148. servers configuration. See HOW TO above.
  149. option dhcp4_slaac6 '0'
  150. Boolean. Some DHCP servers do this natively (dnsmasq). Otherwise
  151. the script provided with this package will try to fabricate SLAAC
  152. IP6 addresses from DHCPv4 MAC records.
  153. option domain 'lan'
  154. Unbound local-zone: <domain> <type>. This is used to suffix all
  155. host records, and maintain a local zone. When dnsmasq is dhcp_link
  156. however, then this option is ignored (dnsmasq does it all).
  157. option domain_type 'static'
  158. Unbound local-zone: <domain> <type>. This allows you to lock
  159. down or allow forwarding of the local zone. Notable types:
  160. static - typical single router setup much like OpenWrt dnsmasq default
  161. refuse - to answer overtly with DNS code REFUSED
  162. deny - to drop queries for the local zone
  163. transparent - to use your manually added forward-zone: or stub-zone: clause
  164. option edns_size '1280'
  165. Bytes. Extended DNS is necessary for DNSSEC. However, it can run
  166. into MTU issues. Use this size in bytes to manage drop outs.
  167. option extended_luci '0'
  168. Boolean. Extends a tab hierarchy in LuCI for advanced configuration.
  169. option extended_stats '0'
  170. Boolean. extended statistics are printed from unbound-control.
  171. Keeping track of more statistics takes time.
  172. option hide_binddata '1'
  173. Boolean. If enabled version.server, version.bind, id.server, and
  174. hostname.bind queries are refused.
  175. option listen_port '53'
  176. Port. Incoming. Where Unbound will listen for queries.
  177. option localservice '1'
  178. Boolean. Prevent DNS amplification attacks. Only provide access to
  179. Unbound from subnets this machine has interfaces on.
  180. option manual_conf '0'
  181. Boolean. Skip all this UCI nonsense. Manually edit the
  182. configuration. Make changes to /etc/unbound/unbound.conf.
  183. option prefetch_root '0'
  184. Boolean. Cache the entire root. Enable Unbound `auth-zone:` clauses for
  185. "." (root), "arpa," "in-addr.arpa," and "ip6.arpa." Obtain complete zone
  186. files from public servers using http or AXFR. (see RFC7706)
  187. option protocol 'mixed'
  188. Unbound can limit its protocol used for recursive queries.
  189. ip4_only - limit issues if you do not have native IPv6
  190. ip6_only - test environment only; could cauase problems
  191. ip6_prefer - both IPv4 and IPv6 but try IPv6 first
  192. mixed - both IPv4 and IPv6
  193. default - Unbound built-in defaults
  194. option query_minimize '0'
  195. Boolean. Enable a minor privacy option. Don't let each server know
  196. the next recursion. Query one piece at a time.
  197. option query_min_strict '0'
  198. Boolean. Query minimize is best effort and will fall back to normal
  199. when it must. This option prevents the fall back, but less than
  200. standard name servers will fail to resolve their domains.
  201. option rebind_localhost '0'
  202. Boolean. Prevent loopback "127.0.0.0/8" or "::1/128" responses.
  203. These may used by black hole servers for good purposes like
  204. ad-blocking or parental access control. Obviously these responses
  205. also can be used to for bad purposes.
  206. option rebind_protection '1'
  207. Level. Block your local address responses from global DNS. A poisoned
  208. reponse within "192.168.0.0/24" or "fd00::/8" could turn a local browser
  209. into an external attack proxy server. IP6 GLA may be vulnerable also.
  210. 0 - Off
  211. 1 - Only RFC 1918 and 4193 responses blocked
  212. 2 - Plus GLA /64 on designated interface(s)
  213. 3 - Plus DHCP-PD range passed down interfaces (not implemented)
  214. option recursion 'passive'
  215. Unbound has many options for recrusion but UCI is bundled for simplicity.
  216. passive - slower until cache fills but kind on CPU load
  217. default - Unbound built-in defaults
  218. aggressive - uses prefetching to handle more requests quickly
  219. option resource 'small'
  220. Unbound has many options for resources but UCI is bundled for simplicity.
  221. tiny - similar to published memory restricted configuration
  222. small - about half of medium
  223. medium - similar to default, but fixed for consistency
  224. default - Unbound built-in defaults
  225. large - about double of medium
  226. option root_age '9'
  227. Days. >90 Disables. Age limit for Unbound root data like root
  228. DNSSEC key. Unbound uses RFC 5011 to manage root key. This could
  229. harm flash ROM. This activity is mapped to "tmpfs," but every so
  230. often it needs to be copied back to flash for the next reboot.
  231. option ttl_min '120'
  232. Seconds. Minimum TTL in cache. Recursion can be expensive without
  233. cache. A low TTL is normal for server migration. A low TTL can be
  234. abused for snoop-vertising (DNS hit counts; recording query IP).
  235. Typical to configure maybe 0~300, but 1800 is the maximum accepted.
  236. option unbound_control '0'
  237. Level. Enables unbound-control application access ports.
  238. 0 - No unbound-control Access, or add your own in 'unbound_ext.conf'
  239. 1 - Unencrypted Local Host Access
  240. 2 - SSL Local Host Access; auto unbound-control-setup if available
  241. 3 - SSL Network Access; auto unbound-control-setup if available
  242. 4 - SSL Network Access; static key/pem files must already exist
  243. option validator '0'
  244. Boolean. Enable DNSSEC. Unbound names this the "validator" module.
  245. option validator_ntp '1'
  246. Boolean. Disable DNSSEC time checks at boot. Once NTP confirms
  247. global real time, then DNSSEC is restarted at full strength. Many
  248. embedded devices don't have a real time power off clock. NTP needs
  249. DNS to resolve servers. This works around the chicken-and-egg.
  250. list domain_forward 'mail.my-isp.com'
  251. Domain. Do not recurse, but rather forward the domains to given DNS
  252. servers found in resolve.conf.auto from WAN DHCP client. This may
  253. provide better access to mirror servers in 'your neigborhood.' This
  254. may be useful in keeping local organization lookups on local subnets.
  255. list domain_insecure 'ntp.somewhere.org'
  256. Domain. Domains that you wish to skip DNSSEC. It is one way around NTP
  257. chicken and egg. Your DHCP servered domains are automatically included.
  258. list rebind_interface 'lan'
  259. Interface (logical). Works with 'rebind_protection' options 2 and 3.
  260. list trigger_interface 'lan' 'wan'
  261. Interface (logical). This option is a work around for netifd/procd
  262. interaction with WAN DHCPv6. Minor RA or DHCP changes in IP6 can
  263. cause netifd to execute procd interface reload. Limit Unbound procd
  264. triggers to LAN and WAN (IP4 only) to prevent restart @2-3 minutes.
  265. ```