Unbound

Siehe auch

Unbound ist ein validierender, rekursiver DNS. Ursprünglich 2004 in Java geschrieben, wurde Unbound 2006 aus Performance-Gründen nach C portiert. Unbound ist modular entworfen: die Komponenten der Server-Software sorgen für die Enhanced Security (DNSSEC) Validierung, unterstützen das Internet Protocol Version 6 (IPv6) sowie eine Client Resolver-API.

Links:

Installation

yum -y install unbound
systemctl enable --now unbound.service

firewall-cmd --permanent --add-service=dns
firewall-cmd --reload

BIND und Unbound lassen sich parallel installieren und gleichzeitig als Service aktivieren, hier muss man also aufpassen.

systemctl status unbound named | grep Active

Minimaler Caching Only DNS

Ein Caching Only Nameserver ist ein nicht-autoritativer Nameserver, der keine eigene Zone (wie beispielsweise example.com) verwaltet. Er muss daher alle eintreffenden DNS-Anfragen über andere Nameserver (Forwarder) auflösen, und speichert das Ergebnis zwecks Caching im lokalen RAM ab. Jeder Cache-Eintrag besitzt ein eigenes Verfallsdatum (TTL, Time To Live), nach dessen Ablauf der Eintrag aus dem Cache gelöscht wird. Die TTL wird dabei durch einen autoritativen Nameserver für diesen Eintrag festgelegt.

Ein Unbound-DNS, der nur Anfragen aus dem Netz 192.0.2.0/24 an den Nameserver 1.1.1.1 weiterleitet und die Antworten zwischenspeichert, sieht so aus:

/etc/unbound/unbound.conf
server:
  interface: 0.0.0.0
  access-control: 192.0.2.0/24 allow
  domain-insecure: example.com
remote-control:
  control-enable: yes       # for unbound-control
forward-zone:
  name: "."
  forward-addr: 1.1.1.1

Unbound validiert per DNSSEC, was mit der letzten Anweisung im „server“-Teil für bestimmte Domains ausgeschaltet werden kann - oft notwendig im eigenen Netz.

Check der Konfigurationsdatei und anschliessender Restart des DNS:

unbound-checkconf
systemctl restart unbound.service

Caching-Test

systemctl restart unbound.service

unbound-control dump_cache
dig @localhost www.duckduckgo.com

unbound-control dump_cache

Interessante Konfigurationseinstellungen

server:
  do-ip4: yes
  do-ip6: no
  do-tcp: no
  do-udp: yes
  hide-identity: yes
  hide-version: yes
  logfile: /var/log/unbound
  verbosity: 5

Minimaler lokaler DNS

Lokaler DNS, der unbekannte Anfragen an extern weiterleitet, inkl. Reverse Lookup.

/etc/unbound/unbound.conf
server:
  access-control: 192.0.2.0/24 allow
  auto-trust-anchor-file: "/var/lib/unbound/root.key"
  chroot: ""
  directory: "/etc/unbound"
  extended-statistics: yes
  harden-below-nxdomain: yes
  harden-dnssec-stripped: yes
  harden-glue: yes
  harden-referral-path: yes
  hide-identity: yes
  hide-version: yes
  interface-automatic: no
  interface: 0.0.0.0
  log-time-ascii: yes
  minimal-responses: yes
  num-threads: 2
  pidfile: "/var/run/unbound/unbound.pid"
  prefetch-key: yes
  prefetch: yes
  rrset-roundrobin: yes
  statistics-cumulative: no
  statistics-interval: 0
  trusted-keys-file: /etc/unbound/keys.d/*.key
  unwanted-reply-threshold: 10000000
  use-caps-for-id: no
  username: "unbound"
  val-clean-additional: yes
  val-log-level: 1
  val-permissive-mode: no
  verbosity: 1

local-zone: "example.com." static
  local-data: "example.com.               10800 IN NS localhost."
  local-data: "example.com.               10800 IN SOA localhost. nobody.invalid. 2022121201 3600 1200 86400 300"
  local-data: "example.com.               10800 IN A 192.0.2.11"
  local-data: "srv-app01.example.com.  10800 IN A 192.0.2.9"
  local-data: "srv-app02.example.com.      10800 IN A 192.0.2.11"
  local-data: "srv-app03.example.com.      10800 IN A 192.0.2.13"

local-zone: "2.0.192.in-addr.arpa." static
  local-data: "2.0.192.in-addr.arpa.      10800 IN NS  example.com."
  local-data: "2.0.192.in-addr.arpa.      10800 IN SOA localhost. nobody.invalid. 2022121201 3600 1200 86400 300"
  local-data: "9.2.0.192.in-addr.arpa.    10800 IN PTR srv-app01.example.com."
  local-data: "11.2.0.192.in-addr.arpa.   10800 IN PTR srv-app02.example.com."
  local-data: "13.2.0.192.in-addr.arpa.   10800 IN PTR srv-app03.example.com."

forward-zone:
  name: "."
  forward-addr: 1.1.1.1
  forward-addr: 1.0.0.1

Troubleshooting

error: failed to read /var/lib/unbound/root.key, error: error reading auto-trust-anchor-file: /var/lib/unbound/root.key, error: validator: error in trustanchors config, error: validator: could not apply configuration settings., fatal error: bad config for validator module

Korrupter Key.

rm -f /var/lib/unbound/root.key
unbound-anchor -a /var/lib/unbound/root.key
chown unbound:unbound /var/lib/unbound/root.key
systemctl restart unbound

Built on 2024-04-18