opyebDNSSECLab

BIND zone syntax — $ORIGIN, $TTL, @ and a correct SOA

Syntax · 9 min

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.
  • $ORIGIN is the base for later relative names: www becomes www.example.com..
  • $TTL is the default for records without their own TTL.
  • @ means the current origin, here example.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

FieldAdvisoryMeaning
SerialYYYYMMDDnnZone version; date-based values are easy to read and rarely collide.
Refresh1200–86400How often a secondary checks the primary.
Retry300–3600Retry interval when the primary is unreachable.
Expire604800–2419200How long data may be kept without contacting the primary.
Minimum300–10800Negative-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.
  • mail without 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 as L_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 DNSSECLab

Frequently 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

Read next

0 bytes of your input sent to a server (advertising and affiliate widgets excluded)