@ -8,35 +8,107 @@ Unbound may be useful on consumer grade embedded hardware. It is *intended* to b
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.
## Work with dnsmasq
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.
## HOW TO Integrate with DHCP
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.
### Serial dnsmasq
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.
**/etc/config/unbound**:
config unbound
option dnsmasq_link_dns '1'
option add_local_fqdn '0'
option add_wan_fqdn '0'
option dhcp_link 'none'
# dnsmasq should not forward your domain to unbound, but if...
option domain 'yourdomain'
option domain_type 'refuse'
option listen_port '1053'
...
**/etc/config/dhcp**:
config dnsmasq
option option noresolv '1'
option resolvfile '<empty>'
option noresolv '1'
option resolvfile ''
option port '53'
list server '127.0.0.1#1053'
list server '::1#1053'
...
### Parallel dnsmasq
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.
**/etc/config/unbound**:
config unbound
option dhcp_link 'dnsmasq'
option listen_port '53'
...
**/etc/config/dhcp**:
config dnsmasq
option domain 'yourdomain'
option noresolv '1'
option resolvfile ''
option port '1053'
...
config dhcp '<name>'
config dhcp 'lan'
list dhcp_option 'option:dns-server,0.0.0.0'
...
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.
### Only odhcpd
Why use dnsmasq you might ask? Well test, try, and review. You can have Unbound and odhcpd only. When odhcpd configures as 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.
*note: You must install unbound-control. The lease file loads are done without starting, stopping, or re-writing conf files.*
*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.*
**/etc/config/unbound**:
config unbound
# name your router in DNS
option add_local_fqdn '1'
option add_wan_fqdn '1'
option dhcp_link 'odhcpd'
# add SLAAC inferred from DHCPv4
option dhcp4_slaac6 '1'
option domain 'lan'
option domain_type 'static'
option listen_port '53'
option rebind_protection '1'
# install unbound-control and set this
option unbound_control '1'
...
**/etc/config/dhcp**:
config dhcp 'lan'
option dhcpv4 'server'
option dhcpv6 'server'
option interface 'lan'
# short times help renew events to refresh dns
option leasetime '4h'
option ra 'server'
option ra_management '1'
# issue your ULA and avoid default [fe80::]
list dns 'fdxx:xxxx:xxxx::1'
config odhcpd 'odhcpd'
option maindhcp '1'
option leasefile '/var/lib/odhcpd/dhcp.leases'
# this is where the magic happens
option leasetrigger '/usr/lib/unbound/odhcpd.sh'
## Back to Manual Configuration
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.
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.
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`.
### Completely Manual (almost)
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`.
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.
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).
**/etc/config/unbound**:
@ -44,46 +116,66 @@ Finally, `root.key` maintenance for DNSKEY RFC5011 would be hard on flash. Unbou
option manual_conf '1'
option root_age '30'
### Hybrid Manual/UCI
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.
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.
## Complete List of UCI Options
**/etc/config/unbound**:
config unbound
Currently only one instance is supported.
option add_local_fqdn '0'
Level. This puts your routers host name in the LAN (local) DNS.
Each level is more detailed and comprehensive.
0 - Disabled
1 - Host Name on only the primary address
2 - Host Name on all addresses found (except link)
3 - FQDN and host name on all addresses (except link)
4 - Above and interfaces named <iface>.<hostname>.<domain>
option add_wan_fqdn '0'
Level. Same as previous option only this applies to the WAN. WAN
are inferred by a UCI `config dhcp` entry that contains the line
option ignore '1'.
option dns64 '0'
Boolean. Enable DNS64 through Unbound in order to bridge networks
that are IPV6 only and IPV4 only (see RFC6052).
option dns64_prefix '64:ff9b::/96'
IPV6 Prefix. The IPV6 prefix wrapped on the IPV4 address for DNS64.
You should use RFC6052 "well known" address, unless you also
You should use RFC6052 "well known" address, unless you also
redirect to a proxy or gateway for your NAT64.
option dnsmasq_gate_name '0'
Boolean. Forward PTR records for interfaces not serving DHCP.
Assume these are WAN. Example dnsmasq option here to provide
logs with a name when your ISP won't link DHCP-DNS.
Boolean. Master link to dnsmasq. Parse /etc/config/dhcp for dnsmasq
options. Forward domain such as "lan" and PTR records for DHCP
interfaces and their deligated subnets, IP4 and IP6.
option dnsmasq_only_local '0'
TODO: not yet implemented
Boolean. Restrict link to dnsmasq. DNS only to local host. Obscure
names of other connected hosts on the network. Example:
"drill -x 198.51.100.17 ~ IN PTR way-out.myrouter.lan"
"drill -x 192.168.10.1 ~ IN PTR guest-wifi.myrouter.lan"
"drill -x 192.168.10.201 ~ NODATA" (insted of james-laptop.lan)
option dhcp_link 'none'
Program Name. Link to one of the supported programs we have scripts
for. You may also need to install a trigger script in the DHCP
servers configuration. See HOW TO above.
option dhcp4_slaac6 '0'
Boolean. Some DHCP servers do this natively (dnsmasq). Otherwise
the script provided with this package will try to fabricate SLAAC
IP6 addresses from DHCPv4 MAC records.
option domain 'lan'
Unbound local-zone: <domain><type>. This is used to suffix all
host records, and maintain a local zone. When dnsmasq is dhcp_link
however, then this option is ignored (dnsmasq does it all).
option domain_type 'static'
Unbound local-zone: <domain><type>. This allows you to lock
down or allow forwarding of your domain, your router host name
without suffix, and leakage of RFC6762 "local."
option edns_size '1280'
Bytes. Extended DNS is necessary for DNSSEC. However, it can run
Bytes. Extended DNS is necessary for DNSSEC. However, it can run
into MTU issues. Use this size in bytes to manage drop outs.
option hide_binddata '1'
Boolean. If enabled version.server, version.bind, id.server, and
Boolean. If enabled version.server, version.bind, id.server, and
hostname.bind queries are refused.
option listen_port '53'
@ -98,11 +190,11 @@ Finally, `root.key` maintenance for DNSKEY RFC5011 would be hard on flash. Unbou
configuration. Make changes to /etc/unbound/unbound.conf.
option protocol 'mixed'
Unbound can limit its protocol: "ip4_only" for ISP behind the time,
"ip6_only" for testing, "ip6_prefer" for ISP with good IP6 support,
or default-all "mixed." This affects the protocol used to
communicate. The DNS responses always include hosts respective IP4
and IP6 data.
Unbound can limit its protocol used for recursive queries.
Set 'ip4_only' to avoid issues if you do not have native IP6.
Set 'ip6_prefer' to possibly improve performance as well as
not consume NAT paths for the client computers.
Do not use 'ip6_only' unless testing.
option query_minimize '0'
Boolean. Enable a minor privacy option. Don't let each server know
@ -164,3 +256,6 @@ Finally, `root.key` maintenance for DNSKEY RFC5011 would be hard on flash. Unbou
List. Domains or pointers that you wish to skip DNSSEC. Your DHCP
domains and pointers in dnsmasq will get this automatically.
## Deprecated UCI
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`)