Sub topic 2
Testing with dig and the configuration checkers
This chapter assumes you can use a Linux shell and edit files as root, that you know IP addresses, ports, and UDP versus TCP, and that you can manage services with systemd. The examples use 192.0.2.10 as the server address and example.com as your zone.
Testing with dig and the configuration checkers
Check every change before you reload a server. dig sends DNS queries, and the checkers catch syntax errors before they break a running service.
sudo unbound-checkconf
sudo named-checkconf
sudo named-checkzone example.com /etc/bind/db.example.com
dig @127.0.0.1 www.example.com A +norecurseThe +norecurse flag asks the server for only the answers it already holds or is authoritative for.
Configuring Unbound as a caching resolver
Unbound is a recursive resolver. It looks up answers for your clients and caches them. Edit /etc/unbound/unbound.conf:
server:
interface: 127.0.0.1
interface: 192.0.2.10
access-control: 127.0.0.0/8 allow
access-control: 192.0.2.0/24 allow
access-control: 0.0.0.0/0 refuse
hide-identity: yes
hide-version: yes
qname-minimisation: yes
prefetch: yesThe access-control lines allow only your own networks to query the resolver. Without them, anyone on the internet could use your server.
Serving local names from Unbound
Unbound can answer for names you define. A static local zone blocks lookups on the internet for that zone and returns only your data:
server:
local-zone: "lab.example." static
local-data: "nas.lab.example. IN A 192.0.2.20"
local-data-ptr: "192.0.2.20 nas.lab.example."Understanding named.conf, options and ACLs
BIND reads /etc/bind/named.conf, which includes the other files. Three block types matter most:
aclnames a list of addresses.optionssets global behavior, such as which addresses BIND listens on.zonedeclares a zone that BIND serves.
acl "trusted" {
127.0.0.1;
192.0.2.0/24;
};
options {
directory "/var/cache/bind";
listen-on { 127.0.0.1; 192.0.2.10; };
allow-query { trusted; };
recursion no;
dnssec-validation auto;
};Writing a zone file
A zone file holds the records for one zone. Save this as /etc/bind/db.example.com:
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2026112801 ; serial
7200 ; refresh
3600 ; retry
1209600 ; expire
3600 ) ; negative caching TTL
IN NS ns1.example.com.
IN MX 10 mail.example.com.
ns1 IN A 192.0.2.10
www IN A 192.0.2.20Increase the serial number each time you edit the file. Secondary servers use it to detect changes. A line that starts with whitespace reuses the previous owner name, so the NS and MX lines apply to the zone apex.
Serving your zone with BIND
Declare the zone in /etc/bind/named.conf.local:
zone "example.com" {
type primary;
file "/etc/bind/db.example.com";
};Run the checks, reload, and then query:
flowchart TD
A[Edit config and zone file] --> B[named-checkconf and named-checkzone]
B -->|errors| A
B -->|pass| C[rndc reload example.com]
C --> D[dig @192.0.2.10 www.example.com A]sudo rndc reload example.com
dig @192.0.2.10 www.example.com A +norecurseExercise
You changed the www record in the zone file, reloaded BIND, and dig still returns the old address. What is the most likely cause, and how do you fix it?
Show answer
The serial number was not increased, so secondary servers and caches do not treat the file as changed. Increase the serial, run named-checkzone, and reload again.