Skip to content
Sign inGet all access
Chapter 7·10 minFree

Running a Zone

Serving your own answers, with BIND in Docker.

Every answer so far came from somebody else’s server. Now one of yours.

A zone file

The format every tutorial assumes, and a control panel hides:

db.example.test
$TTL 3600
@       IN  SOA ns1.example.test. admin.example.test. (
            2026112701  ; serial
            7200        ; refresh
            3600        ; retry
            1209600     ; expire
            900 )       ; minimum
@       IN  NS   ns1.example.test.
@       IN  A    192.0.2.1
ns1     IN  A    192.0.2.1
www     IN  CNAME @
mail    IN  A    192.0.2.2
@       IN  MX   10 mail.example.test.

Eleven lines hold everything chapter 3 covered — apex address, nameserver, alias, mail.

TTL, @ and relative names

Three pieces of syntax do most of the confusing:

Syntax Means
$TTL 3600 the default TTL for records that do not set one
@ the zone’s own name — example.test. here
ns1 relative, so it becomes ns1.example.test.
ns1.example.test. absolute, because of the trailing dot

The SOA record, written

Chapter 3 read one; these are the same five numbers, chosen:

Field Here Chosen because
serial 2026112701 a date plus a counter, so it always increases
refresh 7200 how often a secondary checks
retry 3600 how soon after a failed check
expire 1209600 two weeks before a secondary gives up
minimum 900 negative cache TTL — chapter 5

BIND in Docker

One command, with the zone file mounted in:

terminal
docker run -d --name bind -p 5354:53/udp -p 5354:53/tcp \
    -v $PWD/zone:/etc/bind:ro internetsystemsconsortium/bind9:9.20
Output$ docker run -d --name bind -p 5354:53/udp -p 5354:53/tcp \ -v $PWD/zone:/etc/bind:ro internetsystemsconsortium/bind9:9.20

Querying your own server

Every record in the file answers:

dig @127.0.0.1 -p 5354 +short A example.test
Output192.0.2.1
dig @127.0.0.1 -p 5354 +short MX example.test
Output10 mail.example.test.

The www alias resolves through to the apex, as chapter 3’s chain:

dig @127.0.0.1 -p 5354 +short www.example.test
Outputexample.test.192.0.2.1

And the flag that no earlier chapter could show:

dig @127.0.0.1 -p 5354 +noall +comments A example.test | grep '^;; flags'
Output;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

aa — authoritative answer. This server owns the zone, so the answer is the source. No ra, because it will not recurse:

dig @127.0.0.1 -p 5354 google.com | grep -oE 'status: [A-Z]+'
Outputstatus: REFUSED

That is chapter 5’s REFUSED, now from a server you are running.

Checking a zone

named-checkzone parses the file the way the server will:

terminal
docker exec bind named-checkzone example.test /etc/bind/db.example.test
Outputzone example.test/IN: loaded serial 2026112701OK

Break one line on purpose and it names the line:

terminal
echo 'broken IN A not-an-address' >> zone/db.example.test
docker exec bind named-checkzone example.test /etc/bind/db.example.test
Outputdns_rdata_fromtext: /etc/bind/db.example.test:14: near 'not-an-address': bad dotted quadzone example.test/IN: loading from master file /etc/bind/db.example.test failed: bad dotted quadzone example.test/IN: not loaded due to errors.

Serial numbers and reloads

A secondary fetches a zone only when the serial increases. Forget to bump it and the primary answers correctly while secondaries serve old data.

dig @127.0.0.1 -p 5354 +short SOA example.test | awk '{print $3}'
Output2026112701

Primary and secondary

A secondary holds a copy, fetched by zone transfer:

Primary Secondary
Holds the file you edit a copy
Updates by you editing it AXFR, on a serial bump
Answers with aa yes yes

Both are authoritative, and a resolver cannot tell them apart — which is how chapter 2’s two nameservers both answer for one zone.

Ask our server for a transfer and it declines, which is the correct default:

dig @127.0.0.1 -p 5354 AXFR example.test 2>&1 | grep -oE 'Transfer failed'
OutputTransfer failed

CoreDNS, briefly

The one you meet in Kubernetes. It reads the same zone-file format through a plugin, but its config is a Corefile and clusters mostly use service discovery.

If you are debugging DNS inside a cluster you are debugging CoreDNS, and every dig command in this course works against it unchanged.