Zack Williams | 142f2b5 | 2020-11-22 19:35:44 -0700 | [diff] [blame] | 1 | # unbound templates/unbound.conf.j2 - {{ ansible_managed }} |
| 2 | {# |
| 3 | SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org> |
| 4 | SPDX-License-Identifier: Apache-2.0 |
| 5 | #} |
| 6 | |
| 7 | # general config |
| 8 | server: |
| 9 | port: 53 |
| 10 | do-ip4: yes |
| 11 | do-ip6: no |
| 12 | do-udp: yes |
| 13 | do-tcp: yes |
| 14 | |
| 15 | # logging |
| 16 | verbosity: 1 |
| 17 | |
| 18 | # RFC7816 query name minimization |
| 19 | qname-minimisation: yes |
| 20 | |
| 21 | # access control |
| 22 | {% if unbound_allow_all %} |
| 23 | # allow queries from everywhere |
| 24 | access-control: 0.0.0.0/0 allow |
| 25 | {% else %} |
| 26 | # allow queries from localhost |
| 27 | access-control: 127.0.0.0/24 allow |
| 28 | {% if unbound_allow_zone_ips and dns_zones %} |
| 29 | # allow from networks defined in zones |
| 30 | {% for key, value in dns_zones.items() %} |
| 31 | access-control: {{ value.ip_range }} allow |
| 32 | {% endfor %} |
| 33 | {% endif %} |
| 34 | {% if unbound_allow_ips %} |
| 35 | # listen on specific IPs |
| 36 | {% for ip in unbound_allow_ips %} |
| 37 | interface: {{ ip }} allow |
| 38 | {% endfor %} |
| 39 | {% endif %} |
| 40 | {% endif %} |
| 41 | |
| 42 | # listening interfaces |
| 43 | {% if unbound_listen_default %} |
| 44 | # listen on default IPv4 Address |
| 45 | interface: {{ ansible_default_ipv4.address }} |
| 46 | |
| 47 | {% endif %} |
| 48 | {% if unbound_listen_zone_ips and dns_zones %} |
| 49 | {% for key, value in dns_zones.items() %} |
Zack Williams | 176c124 | 2020-11-30 23:04:13 -0700 | [diff] [blame] | 50 | {% set if_ip = value.ip_range | ipaddr('next_usable') | ipaddr('address') %} |
| 51 | {% if if_ip in ansible_all_ipv4_addresses %} |
Zack Williams | 142f2b5 | 2020-11-22 19:35:44 -0700 | [diff] [blame] | 52 | # listen on IPs defined by dns_zones: {{ key }} |
Zack Williams | 176c124 | 2020-11-30 23:04:13 -0700 | [diff] [blame] | 53 | interface: {{ if_ip }} |
| 54 | {% endif %} |
Zack Williams | 142f2b5 | 2020-11-22 19:35:44 -0700 | [diff] [blame] | 55 | {% endfor %} |
| 56 | |
| 57 | {% endif %} |
| 58 | {% if unbound_listen_ips %} |
| 59 | # listen on specific IPs |
| 60 | {% for ip in unbound_listen_ips %} |
| 61 | interface: {{ ip | ipaddr('address') }} |
| 62 | {% endfor %} |
| 63 | |
| 64 | {% endif %} |
| 65 | # allow unbound to query localhost, where authoritative DNS might be listening |
| 66 | do-not-query-localhost: no |
| 67 | |
| 68 | # disable DNS-over-HTTP (DoH) as it breaks split horizon |
| 69 | # https://support.mozilla.org/en-US/kb/configuring-networks-disable-dns-over-https |
| 70 | # https://support.mozilla.org/en-US/kb/canary-domain-use-application-dnsnet |
| 71 | local-zone: "use-application-dns.net" always_nxdomain |
| 72 | |
| 73 | {% if dns_zones %} |
| 74 | # allow reverse queries for RFC1918 addresses |
| 75 | {% for key, value in dns_zones.items() %} |
| 76 | local-zone: "{{ value.ip_range | unbound_revdns }}" nodefault |
| 77 | |
| 78 | {% endfor %} |
| 79 | |
| 80 | # stub-zones zones that authoritative DNS is serving |
| 81 | {% for key, value in dns_zones.items() %} |
| 82 | stub-zone: |
| 83 | name: "{{ key }}" |
| 84 | stub-addr: {{ unbound_authoritative_server_ip }} |
| 85 | |
| 86 | stub-zone: |
| 87 | name: "{{ value.ip_range | unbound_revdns }}" |
| 88 | stub-addr: {{ unbound_authoritative_server_ip }} |
| 89 | |
| 90 | {% endfor %} |
| 91 | {% endif %} |
Zack Williams | a1c8974 | 2020-12-14 11:01:57 -0700 | [diff] [blame^] | 92 | {% if unbound_forward_zones %} |
| 93 | {% for fz in unbound_forward_zones %} |
| 94 | forward-zone: |
| 95 | name: "{{ fz.name | default('.') }}" |
| 96 | {% for fza in fz.servers %} |
| 97 | forward-addr: {{ fza }} |
| 98 | {% endfor %} |
| 99 | {% endfor %} |
| 100 | |
| 101 | {% endif %} |