Zone File Structure
A zone file consists of:- Directives: Control statements that begin with
$ - Resource Records (RRs): DNS data entries
- Comments: Lines beginning with
;or inline after data
Basic Syntax
Each resource record follows this format:- name: The owner name (can use
@for zone origin) - ttl: Time-to-live in seconds (optional if
$TTLis set) - class: Record class, typically
INfor Internet (optional, defaults to previous) - type: Record type (A, AAAA, MX, etc.)
- rdata: Type-specific data
Directives
$ORIGIN
Sets the origin (base domain) for relative domain names in the zone file.example.com.
Example:
$TTL
Sets the default Time-To-Live for subsequent records that don’t specify a TTL.300- 5 minutes3600- 1 hour (1H)86400- 24 hours (1D)604800- 7 days (7D)
$INCLUDE
Includes another zone file at the current position.SOA Record
Every zone must contain exactly one Start of Authority (SOA) record at the zone apex.SOA Fields
- Primary nameserver: Authoritative master for the zone
- Contact email: Administrator email (first
.becomes@)admin.example.com.→[email protected]- Use backslash for dots in local part:
john\.doe.example.com.→[email protected]
- Serial: Zone version number (increment on changes)
- Refresh: How often secondaries check for updates
- Retry: How long secondaries wait after failed refresh
- Expire: When secondaries stop answering if primary is unreachable
- Negative TTL: How long to cache NXDOMAIN responses
NS Records
Every zone must have at least one Name Server (NS) record.Domain Names
Fully Qualified Domain Names (FQDN)
Domain names ending with a dot are absolute:Relative Domain Names
Names without trailing dots are relative to$ORIGIN:
Special Symbols
@: Represents the current$ORIGIN
Record Class
NSD supports theIN (Internet) class. If omitted, the class is inherited from the previous record.
Comments
Comments begin with semicolon; and continue to end of line:
Multi-line Records
Parentheses allow records to span multiple lines (commonly used for SOA):Complete Zone Example
Validation
Always validate zone files before deploying them to production. Usensd-checkzone to verify syntax and detect errors:
Common Mistakes
NSD requires that zone files are well-formed according to DNS standards. The zone compiler will report errors for:
- Missing SOA record
- Missing NS records
- Malformed domain names
- Invalid record data
- Out-of-zone data
See Also
- Resource Records - All supported RR types
- Zone Validation - Validation rules and nsd-checkzone usage
- RFC 1035 - Domain Names - Implementation and Specification