zone file syntax
The syntax of a zone file in DNS (Domain Name System) is critical for properly configuring DNS records. Here's a breakdown of the syntax used in a typical zone file:
Zone File Syntax Components
TTL (Time to Live):
Defines how long the records in the zone file can be cached by DNS resolvers.
$TTL 86400
Start of Authority (SOA) Record:
Specifies authoritative information about a DNS zone, including the primary name server, administrator's email address, serial number, and refresh intervals.
@ IN SOA ns1.example.com. admin.example.com. ( 2023010101 ; Serial 3600 ; Refresh (1 hour) 1800 ; Retry (30 minutes) 1209600 ; Expire (2 weeks) 86400 ) ; Minimum TTL (1 day)
@
: Represents the domain itself.IN
: Specifies the class (Internet).SOA
: Denotes the type (Start of Authority).
Name Server (NS) Records:
Declares the authoritative name servers for the zone.
@ IN NS ns1.example.com. @ IN NS ns2.example.com.
Address (A) Records:
Maps a hostname to an IPv4 address.
ns1 IN A 192.0.2.1 ns2 IN A 192.0.2.2
IPv6 Address (AAAA) Records:
Maps a hostname to an IPv6 address.
www IN AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Canonical Name (CNAME) Records:
Provides an alias for another domain name.
www IN CNAME example.com.
Mail Exchange (MX) Records:
Specifies the mail servers responsible for receiving email for the domain.
@ IN MX 10 mail.example.com.
Pointer (PTR) Records:
Maps an IP address to a hostname (reverse DNS lookup).
1.2.3.4 IN PTR example.com.
Text (TXT) Records:
Stores arbitrary text associated with a hostname.
@ IN TXT "v=spf1 include:example.com ~all"
Service (SRV) Records:
Specifies the location of services in the domain.
_service._proto IN SRV 10 5 5060 sipserver.example.com.
Additional Syntax Rules
Comments: Lines starting with
;
are comments.; This is a comment
Blank Lines: Blank lines are ignored but can improve readability.
Relative Names: Use
@
to represent the domain itself.Indentation: While not required, proper indentation can enhance readability.
Example Zone File
Here's an example of a complete zone file incorporating various types of records:
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2023010101 ; Serial
3600 ; Refresh (1 hour)
1800 ; Retry (30 minutes)
1209600 ; Expire (2 weeks)
86400 ) ; Minimum TTL (1 day)
; Name Servers
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
; A Records
ns1 IN A 192.0.2.1
ns2 IN A 192.0.2.2
www IN A 192.0.2.3
; AAAA Records
www IN AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334
; CNAME Records
ftp IN CNAME www.example.com.
; MX Records
@ IN MX 10 mail.example.com.
@ IN MX 20 mail2.example.com.
; TXT Records
@ IN TXT "v=spf1 include:example.com ~all"
; SRV Records
_sip._tcp IN SRV 10 5 5060 sipserver.example.com.
Conclusion
Understanding the syntax of a DNS zone file is crucial for configuring DNS records correctly. By following these syntax rules and examples, you can effectively manage DNS zones and ensure proper resolution of domain names to IP addresses and services.
Last updated