Sub topic 10
Writing a zone file
Assume you can use a Linux shell, edit text files, and understand IP addresses, ports, and systemd. This chapter uses BIND primary-server syntax. A zone file is a text file containing DNS resource records for one DNS zone.
Start with the zone apex
The zone example.com has an apex, written as @ inside its zone file. Names without a trailing dot are relative to the zone name. For example, www becomes www.example.com.. A name ending with a dot is fully qualified.
$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.25Understand the records
| Record | Purpose | Example |
|---|---|---|
| SOA | Defines zone authority and timing | `@ IN SOA ns1...` |
| NS | Names an authoritative server | `@ IN NS ns1.example.com.` |
| A | Maps a name to an IPv4 address | `www IN A 192.0.2.20` |
| MX | Names a mail server and its preference | `@ IN MX 10 mail.example.com.` |
| PTR | Maps an address to a name in a reverse zone | `20 IN PTR www.example.com.` |
The SOA record contains the primary name server, an administrative mailbox written with a dot instead of @, and five timing values. The serial identifies the version of the zone. Increase it whenever the zone changes. A date-based serial such as 2026112801 means the first revision on November 28, 2026.
Whitespace at the start of a line reuses the previous owner name. In the example, the indented NS and MX records belong to @. Keep the final dot on names that must not be expanded relative to the zone.
Check the file before loading it
The validation command checks syntax and required records. It does not prove that every address or mail server is reachable.
For a reverse zone, the owner is usually the reversed address portion. For example, address 192.0.2.20 is represented in the 2.0.192.in-addr.arpa zone as:
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2026112801 7200 3600 1209600 3600 )
IN NS ns1.example.com.
20 IN PTR www.example.com.Exercise
What must you change after adding api IN A 192.0.2.30 to a zone file?
Show answer
Add the record and increase the SOA serial to a larger value before validating and reloading the zone.