Sub topic 12
Using BIND as a Recursive Resolver or Forwarder
Assume you can edit BIND configuration, manage systemd services, and use dig. You should also understand IP addresses, UDP, TCP, and firewall rules.
A recursive resolver finds answers for clients. If the answer is not cached, BIND follows DNS referrals from the root servers to the authoritative servers. A forwarder sends the query to one or more upstream resolvers instead. Forwarding can simplify firewall rules and centralize DNS policy.
flowchart TD
C[Client] --> R[BIND resolver]
R -->|cache hit| A[Answer]
R -->|forwarders configured| F[Upstream resolver]
R -->|no forwarders| H[Root and authoritative servers]
F --> A
H --> Acaption: Recursive resolution and forwarding paths alt: A client asks BIND, which answers from cache, forwards to an upstream resolver, or queries the DNS hierarchy directly.
Choosing recursion or forwarding
With full recursion, BIND uses root hints and contacts authoritative servers itself. This gives you control over the complete lookup path, but it requires outbound DNS access and careful DNSSEC and firewall configuration.
With forwarding, BIND sends uncached queries to configured resolvers. Use forward only when BIND must never contact the DNS hierarchy directly. Use forward first when BIND should try the forwarders and then perform full recursion if they fail.
| Mode | Uncached query path | Common reason to use it |
|---|---|---|
| Full recursion | Root, TLD, then authoritative server | Independent resolution |
| `forward only` | Configured upstream resolver | Central policy or restricted networks |
| `forward first` | Forwarder, then full recursion | Forwarder fallback |
A restricted recursive configuration
Place this in the options section of named.conf. Replace the example addresses with your server, client network, and approved upstream resolvers.
options {
directory "/var/cache/bind";
listen-on { 127.0.0.1; 192.0.2.10; };
listen-on-v6 { none; };
recursion yes;
allow-query { 127.0.0.0/8; 192.0.2.0/24; };
allow-recursion { 127.0.0.0/8; 192.0.2.0/24; };
allow-query-cache { 127.0.0.0/8; 192.0.2.0/24; };
forwarders {
192.0.2.53;
192.0.2.54;
};
forward only;
dnssec-validation auto;
};allow-recursion protects the recursive service. Without an access restriction, an Internet-facing server can become an open resolver. Attackers can abuse open resolvers for reflection attacks, and unauthorized clients can consume your bandwidth and cache.
Validate and test
Check the configuration before reloading BIND:
sudo named-checkconf
sudo rndc reload
dig @192.0.2.10 example.org A
dig @192.0.2.10 example.org A +norecurseThe first query tests recursive service. The second asks only for a cached or authoritative answer. A REFUSED response usually indicates an access-control problem. A timeout often indicates that BIND is not listening on the expected address or that a firewall blocks DNS traffic.
Exercise
Which setting prevents BIND from trying root servers after its forwarders fail?
Show answer
forward only; forward first permits fallback to full recursion.