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.

166 lines
8.5 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. ## Work with dnsmasq
  8. Some UCI options will help Unbound and dnsmasq work together in **parallel**. The default DHCP and DNS stub resolver in OpenWrt is dnsmasq, and it will continue to serve this purpose. The following partial examples will make Unbound the primary DNS server, and make dnsmasq only provide DNS to local DHCP.
  9. **/etc/config/unbound**:
  10. config unbound
  11. option dnsmasq_link_dns '1'
  12. ...
  13. **/etc/config/dhcp**:
  14. config dnsmasq
  15. option option noresolv '1'
  16. option resolvfile '<empty>'
  17. option port '1053'
  18. ...
  19. config dhcp '<name>'
  20. list dhcp_option 'option:dns-server,0.0.0.0'
  21. ...
  22. Alternatives are mentioned here for completeness. DHCP event scripts which write host records are difficult to formulate for Unbound, NSD, or Bind. These programs sometimes need to be forcefully reloaded with host configuration, and reloads can bust cache. **Serial** configuration between dnsmasq and Unbound can be made on 127.0.0.1 with an off-port like #1053. This may double cache storage and incur unnecessary transfer delay.
  23. ## Back to Manual Configuration
  24. You don't want UCI, but don't worry. We have UCI for that. However, OpenWrt or LEDE are targeted at embedded machines with flash ROM. The initialization scripts do a few things to protect flash ROM.
  25. 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`.
  26. Finally, `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 this UCI option. Choose how many days to copy from `/var/lib/unbound/root.key` (tmpfs) to `/etc/unbound/root.key` (flash). Keep the DNSKEY updated with your choice of flash activity.
  27. **/etc/config/unbound**:
  28. config unbound
  29. option manual_conf '1'
  30. option root_age '30'
  31. ## Complete List of UCI Options
  32. **/etc/config/unbound**:
  33. config unbound
  34. Currently only one instance is supported.
  35. option dns64 '0'
  36. Boolean. Enable DNS64 through Unbound in order to bridge networks
  37. that are IPV6 only and IPV4 only (see RFC6052).
  38. option dns64_prefix '64:ff9b::/96'
  39. IPV6 Prefix. The IPV6 prefix wrapped on the IPV4 address for DNS64.
  40. You should use RFC6052 "well known" address, unless you also
  41. redirect to a proxy or gateway for your NAT64.
  42. option dnsmasq_gate_name '0'
  43. Boolean. Forward PTR records for interfaces not serving DHCP.
  44. Assume these are WAN. Example dnsmasq option here to provide
  45. logs with a name when your ISP won't link DHCP-DNS.
  46. "dnsmasq.conf: interface-name=way-out.myrouter.lan,eth0.1"
  47. option dnsmasq_link_dns '0'
  48. Boolean. Master link to dnsmasq. Parse /etc/config/dhcp for dnsmasq
  49. options. Forward domain such as "lan" and PTR records for DHCP
  50. interfaces and their deligated subnets, IP4 and IP6.
  51. option dnsmasq_only_local '0'
  52. TODO: not yet implemented
  53. Boolean. Restrict link to dnsmasq. DNS only to local host. Obscure
  54. names of other connected hosts on the network. Example:
  55. "drill -x 198.51.100.17 ~ IN PTR way-out.myrouter.lan"
  56. "drill -x 192.168.10.1 ~ IN PTR guest-wifi.myrouter.lan"
  57. "drill -x 192.168.10.201 ~ NODATA" (insted of james-laptop.lan)
  58. option edns_size '1280'
  59. Bytes. Extended DNS is necessary for DNSSEC. However, it can run
  60. into MTU issues. Use this size in bytes to manage drop outs.
  61. option hide_binddata '1'
  62. Boolean. If enabled version.server, version.bind, id.server, and
  63. hostname.bind queries are refused.
  64. option listen_port '53'
  65. Port. Incoming. Where Unbound will listen for queries.
  66. option localservice '1'
  67. Boolean. Prevent DNS amplification attacks. Only provide access to
  68. Unbound from subnets this machine has interfaces on.
  69. option manual_conf '0'
  70. Boolean. Skip all this UCI nonsense. Manually edit the
  71. configuration. Make changes to /etc/unbound/unbound.conf.
  72. option protocol 'mixed'
  73. Unbound can limit its protocol: "ip4_only" for ISP behind the time,
  74. "ip6_only" for testing, "ip6_prefer" for ISP with good IP6 support,
  75. or default-all "mixed." This affects the protocol used to
  76. communicate. The DNS responses always include hosts respective IP4
  77. and IP6 data.
  78. option query_minimize '0'
  79. Boolean. Enable a minor privacy option. Don't let each server know
  80. the next recursion. Query one piece at a time.
  81. option query_min_strict '0'
  82. Boolean. Query minimize is best effort and will fall back to normal
  83. when it must. This option prevents the fall back, but less than
  84. standard name servers will fail to resolve their domains.
  85. option rebind_localhost '0'
  86. Boolean. Prevent loopback "127.0.0.0/8" or "::1/128" responses.
  87. These may used by black hole servers for good purposes like
  88. ad-blocking or parental access control. Obviously these responses
  89. also can be used to for bad purposes.
  90. option rebind_protection '1'
  91. Boolean. Prevent RFC 1918 Reponses from global DNS. Example a
  92. poisoned reponse within "192.168.0.0/24" could be used to turn a
  93. local browser into an external attack proxy server.
  94. option recursion 'passive'
  95. Unbound has numerous options for how it recurses. This UCI combines
  96. them into "passive," "aggressive," or Unbound's own "default."
  97. Passive is easy on resources, but slower until cache fills.
  98. option resource 'small'
  99. Unbound has numerous options for resources. This UCI gives "tiny,"
  100. "small," "medium," and "large." Medium is most like the compiled
  101. defaults with a bit of balancing. Tiny is close to the published
  102. memory restricted configuration. Small 1/2 medium, and large 2x.
  103. option root_age '30'
  104. Days. >90 Disables. Age limit for Unbound root data like root
  105. DNSSEC key. Unbound uses RFC 5011 to manage root key. This could
  106. harm flash ROM. This activity is mapped to "tmpfs," but every so
  107. often it needs to be copied back to flash for the next reboot.
  108. option ttl_min '120'
  109. Seconds. Minimum TTL in cache. Recursion can be expensive without
  110. cache. A low TTL is normal for server migration. A low TTL can be
  111. abused for snoop-vertising (DNS hit counts; recording query IP).
  112. Typical to configure maybe 0~300, but 1800 is the maximum accepted.
  113. option unbound_control '0'
  114. Boolean. Enables unbound-control application access ports. Enabling
  115. this without the unbound-control package installed is robust.
  116. option validator '0'
  117. Boolean. Enable DNSSEC. Unbound names this the "validator" module.
  118. option validator_ntp '1'
  119. Boolean. Disable DNSSEC time checks at boot. Once NTP confirms
  120. global real time, then DNSSEC is restarted at full strength. Many
  121. embedded devices don't have a real time power off clock. NTP needs
  122. DNS to resolve servers. This works around the chicken-and-egg.
  123. list domain_insecure
  124. List. Domains or pointers that you wish to skip DNSSEC. Your DHCP
  125. domains and pointers in dnsmasq will get this automatically.