Networking & DNS

DNS zone file format explained: read and write BIND zone files

Understand the structure of a DNS zone file: $ORIGIN and $TTL, the @ symbol, relative vs absolute names, record syntax, comments, and how to validate, export and import zones.

IntermediateDNS2 min read

A DNS zone file is a plain-text file that lists every record for a domain in the standard format defined in RFC 1035. BIND uses zone files directly, and most DNS providers can import and export them. Knowing the zone file format lets you move DNS between providers and spot errors quickly.

Before you start

You can export your zone from most DNS hosts. On WHM, administrators can view zones under DNS Functions → Edit DNS Zone; on your own server, BIND zone files are in /etc/bind/ or /var/named/.

A complete example

$ORIGIN example.com.
$TTL 3600
@       IN  SOA  ns1.example.com. hostmaster.example.com. (
                 2026061001 3600 900 1209600 300 )
        IN  NS   ns1.example.com.
        IN  NS   ns2.example.com.
@       IN  A    203.0.113.50
www     IN  CNAME @
mail    IN  A    203.0.113.60
@       IN  MX   10 mail
@       IN  TXT  "v=spf1 mx ~all"
ftp 300 IN  A    203.0.113.50   ; short TTL for this record

Directives

  • $ORIGIN – the domain appended to relative names. Usually the zone name.
  • $TTL – default TTL for records that don't specify one.
  • $INCLUDE – include another file (rarely used).

Record syntax

name  [ttl]  [class]  type  data
FieldNotes
name@ means the origin; blank means "same name as the previous line"
ttlOptional; seconds, or units like 1h in BIND
classAlmost always IN (internet)
typeA, AAAA, CNAME, MX, TXT, NS, SRV, CAA…
dataType-specific: IP, hostname, priority + host, quoted text…

Relative vs absolute names

This is the source of most zone file mistakes:

  • mail.example.com. with a trailing dot is absolute – used as written.
  • mail without a dot is relative – $ORIGIN is appended, giving mail.example.com.
  • mail.example.com without the dot becomes mail.example.com.example.com. – a classic bug.

Comments and multi-line records

  • A semicolon ; starts a comment.
  • Parentheses let one record span several lines, as in the SOA above.
  • TXT data longer than 255 characters is written as several quoted strings: "part1" "part2".

Validate a zone file

named-checkzone example.com /path/to/db.example.com

It reports syntax errors, CNAME conflicts and missing records, and prints the serial it loaded.

Export and import

  1. Export from the old provider (many have a "export zone file" or BIND format option).
  2. Review it: remove the provider's own NS and SOA if the new provider creates them, and check for records pointing at the old host.
  3. Import at the new provider, then compare: dig @old-ns example.com ANY is unreliable, so query key records (A, MX, TXT, CNAMEs) individually on both.

FAQ: DNS zone files

Do I need to edit zone files on cPanel?

No. Use the Zone Editor; cPanel writes the zone file and updates the serial for you.

What does a blank name mean?

It repeats the name from the previous record – handy for several records on one name, but easy to misread.

Is the record order important?

No, except that SOA is conventionally first. Resolvers don't see the file order.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.