BIND zone syntax — $ORIGIN, $TTL, @ and a correct SOA
In one line: Zone file structure and omission rules, what each SOA timer means, and the CNAME, MX and TXT details that are most often wrong.
A zone file is a plain text list of every record for a domain. The syntax looks simple, but omission rules and relative names quietly create records you did not intend.
1. Structure
$ORIGIN example.com.
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2026113001 ; serial
7200 ; refresh
3600 ; retry
1209600 ; expire
3600 ) ; minimum
IN NS ns1.example.com.
IN NS ns2.example.com.
IN MX 10 mail.example.com.
IN TXT "v=spf1 mx -all"
IN CAA 0 issue "letsencrypt.org"
ns1 IN A 192.0.2.1
ns2 IN A 192.0.2.2
mail IN A 192.0.2.10
www IN CNAME example.com.
$ORIGINis the base for later relative names:wwwbecomeswww.example.com..$TTLis the default for records without their own TTL.@means the current origin, hereexample.com..- A line starting with whitespace omits the owner and inherits the previous one.
- Parentheses allow line breaks; everything after a semicolon is a comment.
2. SOA fields
| Field | Advisory | Meaning |
|---|---|---|
| Serial | YYYYMMDDnn | Zone version; date-based values are easy to read and rarely collide. |
| Refresh | 1200–86400 | How often a secondary checks the primary. |
| Retry | 300–3600 | Retry interval when the primary is unreachable. |
| Expire | 604800–2419200 | How long data may be kept without contacting the primary. |
| Minimum | 300–10800 | Negative-answer cache TTL (historically the default TTL). |
A serial that simply increments works, but a date-based value shows when the zone last changed. The linter warns when the serial is not ten digits.
3. Names and the trailing dot
example.com.with a trailing dot is absolute.mailwithout one is relative and gets the origin appended.- Forgetting the dot on an MX, NS, CNAME or SRV target can produce
mail.example.com.example.com.; the linter flags it asL_TARGET_RELATIVE.
4. CNAME rules
A CNAME cannot coexist with any other record at the same name (RFC 1034, RFC 2181).
- The apex always has SOA and NS, so it cannot carry a CNAME.
- CNAME plus A, or CNAME plus TXT, at one name is an error.
- Chained CNAMEs lengthen resolution, and a missing final target breaks the answer.
5. TXT and special characters
TXT values are quoted. One string may hold at most 255 bytes; longer values are split into several strings.
_dmarc IN TXT ( "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com;"
" ruf=mailto:forensics@example.com; pct=100" )
Wrapping a single string across lines can inject a newline and spaces into the value. Close one string and open another instead.
6. Before applying
named-checkzone example.com example.com.zone
The DNSSECLab linter is the fast check while editing; named-checkzone and live queries remain the final authority.
Computing a single DS record makes the relationship between the key tag and the digest concrete.
Open DNSSECLabFrequently asked questions
What if $TTL and the record TTL differ?
The record TTL wins for that record. If records of the same name and type carry different TTLs, cache behaviour becomes hard to predict, and the linter warns.
Must the SOA serial use a date?
No, it only has to increase. A date-based value makes changes easier to read and reduces secondary synchronisation mistakes.
Why can't the apex carry a CNAME?
The apex must have SOA and NS, and a CNAME cannot exist beside other records at the same name. The two rules conflict, so an apex CNAME is an invalid zone.
References
- RFC 1035 — Domain Names: Implementation and Specification
- RFC 1912 — Common DNS Operational and Configuration Errors
- RFC 2181 — Clarifications to the DNS Specification
- BIND 9 Administrator Reference Manual — named-checkzone
Read next
- Turning a DNSKEY into a DS record — key tag and digest, step by stepHow to derive the key tag from a DNSKEY and build a SHA-256 DS record, with a worked example and the order in which parent and child zones are updated.
- DNSKEY flags and algorithms — telling KSK from ZSK and choosing oneWhat flags 256 and 257 mean together with the SEP and REVOKE bits, why protocol must be 3, and how to choose between algorithms 8, 13, 14, 15 and 16.
- CAA, SPF and TXT lint — the mistakes that block certificates and emailCAA flags, tags and values, the SPF ten-lookup limit, the single-SPF rule, and splitting TXT strings at 255 bytes.