Sub topic 11
Serving your zone with BIND
This chapter turns BIND into an authoritative-only server for one zone, example.com. It assumes you have read the earlier chapters on resource records, server roles, and the structure of named.conf. It also assumes BIND is installed, port 53 is free, and you can use dig. Recursive mode, zone transfers, and views are covered in later chapters.
What the server has to do
An authoritative server answers queries only for zones it holds, and it answers them from its own data. It never goes out to the internet to look up other names. That keeps the configuration small. You need three things:
- Options that disable recursion and set listening addresses.
- A
zonestatement that points to a file. - A zone file with valid records.
The configuration
This is the authoritative-only configuration. On Debian and Ubuntu, put the options block in named.conf.options and the zone block in named.conf.local. On the RHEL family, everything normally lives in /etc/named.conf and zone files live under /var/named.
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 { any; };
recursion no;
dnssec-validation auto;
};
zone "example.com" {
type primary;
file "/etc/bind/db.example.com";
allow-transfer { 192.0.2.11; };
};Each setting does one job:
recursion no;stops the server from resolving names it is not authoritative for. Clients asking for other names getREFUSED. This is what prevents an open resolver.allow-query { any; };is correct here. An authoritative server must be reachable by the whole internet, or nobody can resolve your names.type primary;is the current keyword. Older documentation saysmaster, which BIND still accepts.allow-transferlimits full zone copies (AXFR) to your secondary at 192.0.2.11. The default would let anyone download your whole zone.dnssec-validation auto;only matters if the server also resolves. It is harmless here.- The
trustedACL is not used by this zone. You will use it in the hardening chapter, for example inallow-recursion.
BIND sends NOTIFY messages to the zone's listed name servers by default (notify yes;). You do not need to configure that for the secondary.
The zone file
$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 NS ns2.example.com.
IN MX 10 mail.example.com.
ns1 IN A 192.0.2.10
ns2 IN A 192.0.2.11
www IN A 192.0.2.20
mail IN A 192.0.2.25The file has several details that cause most real-world errors.
Names and the trailing dot
@ stands for the zone name, example.com.. A name with a trailing dot is absolute. A name without one gets the zone name appended. If you wrote ns1.example.com without the final dot, the server would read it as ns1.example.com.example.com.. Every fully written name in the SOA, NS, and MX records needs the dot.
The lines that start with whitespace (the NS and MX records) reuse the previous owner name, which is the apex. They do not begin a new name.
The SOA record
- The first name is the primary name server. The second is the responsible mailbox, with the first dot standing for
@. Sohostmaster.example.com.means [email protected]. serialis the version number. Secondaries compare it with their own copy and transfer the zone only if yours is higher. The formatYYYYMMDDnngives you 100 changes per day.refreshandretrytell secondaries how often to check for changes and how soon to retry after a failure. NOTIFY normally makes the refresh interval irrelevant.expireis how long a secondary keeps answering if it cannot reach the primary. After this time it stops answering for the zone.- The last field is the negative caching TTL. It controls how long resolvers remember that a name does not exist. In older documentation this field is called "minimum".
Rules about record content
- An MX or NS target must be a name with an address record. It must not be a CNAME.
- A CNAME cannot share a name with any other record, so you cannot make the apex a CNAME.
- This example has no A record for
example.com.itself. Add@ IN A 192.0.2.20if the bare domain should serve a website. - If
ns1andns2are inside the zone they serve, the parent zone (through your registrar) needs glue records with their addresses. Without glue, resolvers cannot find your name servers.
Check, load, and query
Always validate before you load. A syntax error found by the checker costs nothing. The same error found by a reload can leave a zone unserved.
sudo named-checkconf
sudo named-checkzone example.com /etc/bind/db.example.com
sudo rndc reload example.com
dig @127.0.0.1 www.example.com A +norecurse
dig @127.0.0.1 example.com SOA +short
dig @127.0.0.1 example.org A +norecursenamed-checkzone prints the loaded serial and OK when the file is valid. For the first query, check three parts of the reply:
status: NOERROR- the flag
aa, which means the server answered as authoritative for the zone - an ANSWER section containing
192.0.2.20
The SOA query with +short should print ns1.example.com. hostmaster.example.com. 2026112801 7200 3600 1209600 3600. The third query, for a name outside your zone, should return status: REFUSED. That confirms recursion is off.
The first start uses systemctl enable --now bind9 on Debian and Ubuntu, and systemctl enable --now named on the RHEL family. After that, use rndc reload example.com to reload one zone without restarting the daemon.
Common errors
| Symptom | Likely cause |
|---|---|
| Secondary keeps old data | The serial was not increased, or it went down |
| `SERVFAIL` for the zone | The file failed to load at startup. Check the log for the line number |
| Names such as `ns1.example.com.example.com` | A trailing dot is missing |
| `REFUSED` for your own zone | The `zone` block is missing, or `allow-query` excludes the client |
| Zone file "permission denied" | The `bind` or `named` user cannot read the file, or AppArmor or SELinux blocks the path |
| No `aa` flag in the reply | You queried a cache or a server that is not authoritative for the name |
Exercise
You change the address of www in the zone file, run named-checkzone (it reports OK), and run rndc reload example.com. The primary now answers with the new address, but the secondary still serves the old one. What did you forget, and why does the check not catch it?
Show answer
You did not increase the SOA serial. Secondaries transfer the zone only when the primary's serial is higher than their own. named-checkzone verifies syntax and consistency, not whether you bumped the version, so it reports OK. Increase the serial (for example, to 2026112802) and reload again.
Exercise
A query for www.example.com returns the right address but no aa flag, and a query for example.org returns an answer instead of REFUSED. What are the likely explanations?
Show answer
The server you queried is probably not the authoritative-only BIND you configured. It is probably a recursive resolver or a cache. Either that, or recursion no; is not in effect on the server. Check that you used the right address with dig @192.0.2.10, confirm named-checkconf -p shows recursion no;, and check that the daemon was reloaded.