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.

264 lines
13 KiB

  1. # Unbound Recursive DNS Server with UCI
  2. ## Unbound Description
  3. Unbound is a validating, recursive, and caching DNS resolver. The C implementation of Unbound is developed and maintained by [NLnet Labs](https://www.unbound.net/). 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, 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 work at the raw "unbound.conf" level.
  7. ## Adblocking
  8. The UCI scripts will work with OpenWrt/pacakages/net/adblock (2.3.0 and above) 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. config unbound
  15. option add_local_fqdn '0'
  16. option add_wan_fqdn '0'
  17. option dhcp_link 'none'
  18. # dnsmasq should not forward your domain to unbound, but if...
  19. option domain 'yourdomain'
  20. option domain_type 'refuse'
  21. option listen_port '1053'
  22. ...
  23. **/etc/config/dhcp**:
  24. config dnsmasq
  25. option domain 'yourdomain'
  26. option noresolv '1'
  27. option resolvfile '/tmp/resolv.conf.auto'
  28. option port '53'
  29. list server '127.0.0.1#1053'
  30. list server '::1#1053'
  31. ...
  32. ### Parallel dnsmasq
  33. 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.
  34. **/etc/config/unbound**:
  35. config unbound
  36. option dhcp_link 'dnsmasq'
  37. option listen_port '53'
  38. ...
  39. **/etc/config/dhcp**:
  40. config dnsmasq
  41. option domain 'yourdomain'
  42. option noresolv '1'
  43. option resolvfile '/tmp/resolv.conf.auto'
  44. option port '1053'
  45. ...
  46. config dhcp 'lan'
  47. # dnsmasq may not issue DNS option if not std. configuration
  48. list dhcp_option 'option:dns-server,0.0.0.0'
  49. ...
  50. ### Only odhcpd
  51. Why use dnsmasq you might ask? Well test, try, and review. You can have Unbound and odhcpd only. When odhcpd configures each DHCP lease, it will call a script. The script provided with Unbound will read the lease file and enter DHCP-DNS records as much as dnsmasq once did. You **must install** `unbound-control`, because the lease records are added and removed without starting, stopping, flushing cache, or re-writing conf files.
  52. *note: if you run the default LEDE/OpenWrt setup with dnsmasq and odhcpd, then use the link to dnsmasq. Unbound will pole dnsmasq. dnsmasq merges its lease file and odhcpd lease file.*
  53. **/etc/config/unbound**:
  54. config unbound
  55. # name your router in DNS
  56. option add_local_fqdn '1'
  57. option add_wan_fqdn '1'
  58. option dhcp_link 'odhcpd'
  59. # add SLAAC inferred from DHCPv4
  60. option dhcp4_slaac6 '1'
  61. option domain 'lan'
  62. option domain_type 'static'
  63. option listen_port '53'
  64. option rebind_protection '1'
  65. # install unbound-control and set this
  66. option unbound_control '1'
  67. ...
  68. **/etc/config/dhcp**:
  69. config dhcp 'lan'
  70. option dhcpv4 'server'
  71. option dhcpv6 'server'
  72. option interface 'lan'
  73. # short times help renew events to refresh dns
  74. option leasetime '4h'
  75. option ra 'server'
  76. option ra_management '1'
  77. # issue your ULA and avoid default [fe80::]
  78. list dns 'fdxx:xxxx:xxxx::1'
  79. config odhcpd 'odhcpd'
  80. option maindhcp '1'
  81. option leasefile '/var/lib/odhcpd/dhcp.leases'
  82. # this is where the magic happens
  83. option leasetrigger '/usr/lib/unbound/odhcpd.sh'
  84. ## Back to Manual Configuration
  85. 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.
  86. ### Completely Manual (almost)
  87. 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`.
  88. 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).
  89. **/etc/config/unbound**:
  90. config unbound
  91. option manual_conf '1'
  92. option root_age '30'
  93. ### Hybrid Manual/UCI
  94. 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.
  95. The former will be added to the end of the `server:` clause. The later will be added to the end of the file for extended `forward:` 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.
  96. ## Complete List of UCI Options
  97. **/etc/config/unbound**:
  98. config unbound
  99. Currently only one instance is supported.
  100. option add_local_fqdn '0'
  101. Level. This puts your routers host name in the LAN (local) DNS.
  102. Each level is more detailed and comprehensive.
  103. 0 - Disabled
  104. 1 - Host Name on only the primary address
  105. 2 - Host Name on all addresses found (except link)
  106. 3 - FQDN and host name on all addresses (except link)
  107. 4 - Above and interfaces named <iface>.<hostname>.<domain>
  108. option add_wan_fqdn '0'
  109. Level. Same as previous option only this applies to the WAN. WAN
  110. are inferred by a UCI `config dhcp` entry that contains the line
  111. option ignore '1'.
  112. option dns64 '0'
  113. Boolean. Enable DNS64 through Unbound in order to bridge networks
  114. that are IPV6 only and IPV4 only (see RFC6052).
  115. option dns64_prefix '64:ff9b::/96'
  116. IPV6 Prefix. The IPV6 prefix wrapped on the IPV4 address for DNS64.
  117. You should use RFC6052 "well known" address, unless you also
  118. redirect to a proxy or gateway for your NAT64.
  119. option dhcp_link 'none'
  120. Program Name. Link to one of the supported programs we have scripts
  121. for. You may also need to install a trigger script in the DHCP
  122. servers configuration. See HOW TO above.
  123. option dhcp4_slaac6 '0'
  124. Boolean. Some DHCP servers do this natively (dnsmasq). Otherwise
  125. the script provided with this package will try to fabricate SLAAC
  126. IP6 addresses from DHCPv4 MAC records.
  127. option domain 'lan'
  128. Unbound local-zone: <domain> <type>. This is used to suffix all
  129. host records, and maintain a local zone. When dnsmasq is dhcp_link
  130. however, then this option is ignored (dnsmasq does it all).
  131. option domain_type 'static'
  132. Unbound local-zone: <domain> <type>. This allows you to lock
  133. down or allow forwarding of your domain, your router host name
  134. without suffix, and leakage of RFC6762 "local."
  135. option edns_size '1280'
  136. Bytes. Extended DNS is necessary for DNSSEC. However, it can run
  137. into MTU issues. Use this size in bytes to manage drop outs.
  138. option hide_binddata '1'
  139. Boolean. If enabled version.server, version.bind, id.server, and
  140. hostname.bind queries are refused.
  141. option listen_port '53'
  142. Port. Incoming. Where Unbound will listen for queries.
  143. option localservice '1'
  144. Boolean. Prevent DNS amplification attacks. Only provide access to
  145. Unbound from subnets this machine has interfaces on.
  146. option manual_conf '0'
  147. Boolean. Skip all this UCI nonsense. Manually edit the
  148. configuration. Make changes to /etc/unbound/unbound.conf.
  149. option protocol 'mixed'
  150. Unbound can limit its protocol used for recursive queries.
  151. Set 'ip4_only' to avoid issues if you do not have native IP6.
  152. Set 'ip6_prefer' to possibly improve performance as well as
  153. not consume NAT paths for the client computers.
  154. Do not use 'ip6_only' unless testing.
  155. option query_minimize '0'
  156. Boolean. Enable a minor privacy option. Don't let each server know
  157. the next recursion. Query one piece at a time.
  158. option query_min_strict '0'
  159. Boolean. Query minimize is best effort and will fall back to normal
  160. when it must. This option prevents the fall back, but less than
  161. standard name servers will fail to resolve their domains.
  162. option rebind_localhost '0'
  163. Boolean. Prevent loopback "127.0.0.0/8" or "::1/128" responses.
  164. These may used by black hole servers for good purposes like
  165. ad-blocking or parental access control. Obviously these responses
  166. also can be used to for bad purposes.
  167. option rebind_protection '1'
  168. Boolean. Prevent RFC 1918 Reponses from global DNS. Example a
  169. poisoned reponse within "192.168.0.0/24" could be used to turn a
  170. local browser into an external attack proxy server.
  171. option recursion 'passive'
  172. Unbound has numerous options for how it recurses. This UCI combines
  173. them into "passive," "aggressive," or Unbound's own "default."
  174. Passive is easy on resources, but slower until cache fills.
  175. option resource 'small'
  176. Unbound has numerous options for resources. This UCI gives "tiny,"
  177. "small," "medium," and "large." Medium is most like the compiled
  178. defaults with a bit of balancing. Tiny is close to the published
  179. memory restricted configuration. Small 1/2 medium, and large 2x.
  180. option root_age '30'
  181. Days. >90 Disables. Age limit for Unbound root data like root
  182. DNSSEC key. Unbound uses RFC 5011 to manage root key. This could
  183. harm flash ROM. This activity is mapped to "tmpfs," but every so
  184. often it needs to be copied back to flash for the next reboot.
  185. option ttl_min '120'
  186. Seconds. Minimum TTL in cache. Recursion can be expensive without
  187. cache. A low TTL is normal for server migration. A low TTL can be
  188. abused for snoop-vertising (DNS hit counts; recording query IP).
  189. Typical to configure maybe 0~300, but 1800 is the maximum accepted.
  190. option unbound_control '0'
  191. Boolean. Enables unbound-control application access ports. Enabling
  192. this without the unbound-control package installed is robust.
  193. option validator '0'
  194. Boolean. Enable DNSSEC. Unbound names this the "validator" module.
  195. option validator_ntp '1'
  196. Boolean. Disable DNSSEC time checks at boot. Once NTP confirms
  197. global real time, then DNSSEC is restarted at full strength. Many
  198. embedded devices don't have a real time power off clock. NTP needs
  199. DNS to resolve servers. This works around the chicken-and-egg.
  200. list domain_insecure
  201. List. Domains or pointers that you wish to skip DNSSEC. Your DHCP
  202. domains and pointers in dnsmasq will get this automatically.
  203. ## Deprecated UCI
  204. The dnsmasq specific UCI will still work as well as they did, but please use `option dhcp_link 'dnsmasq'` above. Local host name and WAN host name will be lifted and configured from DHCP UCI subpart dnsmasq. (`dnsmasq_gate_name`, `dnsmasq_link_dns`, `dnsmasq_only_local`)