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 recordDirectives
- $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| Field | Notes |
|---|---|
| name | @ means the origin; blank means "same name as the previous line" |
| ttl | Optional; seconds, or units like 1h in BIND |
| class | Almost always IN (internet) |
| type | A, AAAA, CNAME, MX, TXT, NS, SRV, CAA… |
| data | Type-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.mailwithout a dot is relative –$ORIGINis appended, givingmail.example.com.mail.example.comwithout the dot becomesmail.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.comIt reports syntax errors, CNAME conflicts and missing records, and prints the serial it loaded.
Export and import
- Export from the old provider (many have a "export zone file" or BIND format option).
- 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.
- Import at the new provider, then compare:
dig @old-ns example.com ANYis 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.
