What is a Zone File?
A Zone File is a plain text file stored on authoritative nameservers that contains the complete DNS configuration for a domain, including all resource records that define how the domain's DNS queries should be resolved.
Zone File Structure
; Zone file for example.com
$TTL 86400 ; Default TTL (24 hours)
$ORIGIN example.com.
; SOA Record (Start of Authority)
@ IN SOA ns1.example.com. admin.example.com. (
2024010101 ; Serial number (YYYYMMDDNN)
3600 ; Refresh (1 hour)
900 ; Retry (15 minutes)
604800 ; Expire (1 week)
86400 ; Minimum TTL (24 hours)
)
; Nameserver Records
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
; A Records (IPv4)
@ IN A 192.0.2.1
www IN A 192.0.2.1
mail IN A 192.0.2.10
; AAAA Records (IPv6)
@ IN AAAA 2001:db8::1
; MX Records (Mail)
@ IN MX 10 mail.example.com.
@ IN MX 20 backup-mail.example.com.
; CNAME Records (Aliases)
blog IN CNAME www.example.com.
; TXT Records
@ IN TXT "v=spf1 mx -all"
Common Record Types
| Record | Purpose | Example Value |
|---|---|---|
| SOA | Zone authority and timing | Serial, refresh, retry values |
| NS | Nameserver delegation | ns1.example.com. |
| A | IPv4 address mapping | 192.0.2.1 |
| AAAA | IPv6 address mapping | 2001:db8::1 |
| MX | Mail server routing | 10 mail.example.com. |
| CNAME | Domain aliasing | www.example.com. |
| TXT | Text data (SPF, DKIM, etc.) | "v=spf1 mx -all" |
| SRV | Service location | _sip._tcp.example.com. |
Zone File Directives
| Directive | Purpose | Example |
|---|---|---|
| $TTL | Default time-to-live | $TTL 86400 |
| $ORIGIN | Base domain for relative names | $ORIGIN example.com. |
| @ | Shorthand for $ORIGIN domain | @ IN A 192.0.2.1 |
Best Practices
1. Increment serial: Update serial number with every change for proper zone transfers
2. Use FQDN: End fully qualified domain names with a trailing dot
3. Set appropriate TTLs: Lower for frequently changing records, higher for stable ones
4. Document changes: Add comments with semicolons for record purposes
5. Validate syntax: Use named-checkzone or similar tools before deploying
Zone Transfer Security
Zone transfers (AXFR) replicate zone files between primary and secondary nameservers. Restrict transfers to authorized IPs to prevent information disclosure.
Zone files form the foundation of DNS configuration, defining how domain names resolve to IP addresses and services.