Some practical advice on
DNS zone file construction

Updated: 2005-01-07
Created: 2004-06-15

Licensing and disclaimer of warranty

For DNS, the OReilly book is probably the nicest and it explains both the easy bits and the subtle things. What follows is a fairly general homily with things that you already know, but just to present a coherent picture.

Some general principles

Zones and zone files

My guidelines for writing zone files

General principles:

Specifically about RRs (resource records, represented by lines inside a zone file):

Some personal style recommendations

Some example zone files

A simple forward domain

; -*- outline-regexp: ";;* " -*- vim:ft=bindzone 
$TTL            1H
@                       SOA     DNS hostmaster (
                                  ;serial       refresh retry   expire  negTTL
                                  2004022300    1H      30M     20D     1H
;                                 YYYYmmDDnn
                                )
@                       RP      root rp
@                       TXT     "Zone for example.org"
rp                      TXT     "example.org hostmaster"
;
; '@', name servers and mail exchangers cannot be 'CNAME's.
;
@                       NS      DNS
;
@                       MX 1    SMTP
;
@                       A       IPaddress
;
DNS                     A       IPaddress
SMTP                    A       IPaddress
;
POP3                    CNAME   @
WWW                     CNAME   @
FTP                     CNAME   @
;
; Anti-SPAM domains.
;
remove-this             TXT     "This is a spamtrap subdomain. Remove it from email addresses."
;
; Recipient-specific domains.
;
*.to                    MX 1    SMTP
*.to                    MX 99   MXbackup.Gradwell.net.
*.for                   MX 1    SMTP
*.for                   MX 99   MXbackup.Gradwell.net.

A more complete forward domain

; -*- outline-regexp: ";;* " -*- vim:ft=bindzone
$TTL            1H
@                       SOA     DNS hostmaster (
                                  ;serial       refresh retry   expire  negTTL
                                  2004060900    1H      30M     20D     1H
;                                 YYYYmmDDnn
                                )
@                       RP      root rp
@                       TXT     "Zone for example.com"
rp                      TXT     "example.com hostmaster"
@                       LOC     52 14 05 N 00 08 50 E 50m
;
; '@', name servers and mail exchangers cannot be 'CNAME's.
;
@                       NS      ns1.Gradwell.net.
@                       NS      ns2.Gradwell.net.
@                       NS      DNS
;
hq                      NS      DNS
;
@                       MX 10   @
@                       MX 20   SMTP
@                       MX 30   SMTP2
@                       MX 99   MXbackup.Gradwell.net.
;
@                       A       IPaddress
IP6                     AAAA    IPv6address
;
DNS                     A       IPaddress
DNS.IP6                 AAAA    IPv6address
SMTP                    A       IPaddress
SMTP.IP6                AAAA    IPv6address
SMTP2                   A       IPaddress
SMTP2.IP6               AAAA    IPv6address
;
POP3                    CNAME   @
POP3.IP6                CNAME   IP6
WWW                     CNAME   @
WWW.IP6                 CNAME   IP6
FTP                     CNAME   @
FTP.IP6                 CNAME   IP6
SSL                     CNAME   @
SSL.IP6                 CNAME   IP6
H323                    CNAME   @
H323.IP6                CNAME   IP6
SIP                     CNAME   @
SIP.IP6                 CNAME   IP6
;
; The IPv6 network is 2001:0618:0400:b4eb::/64.
gw.IP6                  AAAA    IPv6address
net.IP6                 AAAA    IPv6prefix::
net.IP6                 PTR     IPv6reversemap.IP6.ARPA.
net.IP6                 PTR     IPv6reversemap.IP6.INT.
sm.IP6                  AAAA    ffff:ffff:ffff:ffff::
;
; Anti-SPAM domains.
;
0406.exp                TXT     "This subdomain loses its MX RR sometime after Jun 2004"
0406.exp                MX 1    SMTP
;
remove-this             TXT     "This is a spamtrap subdomain. Remove it from email addresses."
;
; Recipient-specific domains. Remember special rules about '*'.
;
*.to                    MX 1    SMTP
*.to                    MX 99   MXbackup.Gradwell.net.
*.for                   MX 1    SMTP
*.for                   MX 99   MXbackup.Gradwell.net.
;
; Dynamic subzone.
;
;dyn                    NS      @

One might want to add a section for listing services:

;
;domain [ttl]           IN NAPTR order preference flags service regexp target
@                       NAPTR   0 0 "s" "DNS+D2U"       "" _dns._udp
@                       NAPTR   0 0 "s" "DNS+D2T"       "" _dns._tcp
@                       NAPTR   0 0 "s" "SMTP+D2T"      "" _pop3._tcp
@                       NAPTR   0 0 "s" "SSMTP+D2T"     "" _ssmtp._tcp
@                       NAPTR   0 0 "s" "POP3+D2T"      "" _pop3._tcp
@                       NAPTR   0 0 "s" "POP3+D2T"      "" _pop3._tcp
@                       NAPTR   0 0 "s" "POP3S+D2T"     "" _pop3s._tcp
@                       NAPTR   0 0 "s" "HTTP+D2T"      "" _http._tcp
@                       NAPTR   0 0 "s" "HTTPS+D2T"     "" _https._tcp
@                       NAPTR   0 0 "s" "FTP+D2T"       "" _ftp._tcp
@                       NAPTR   0 0 "s" "H323+D2T"      "" _h323._tcp
@                       NAPTR   0 0 "s" "SIPS+D2T"      "" _sips._tcp
@                       NAPTR   1 0 "s" "SIP+D2T"       "" _sip._tcp
@                       NAPTR   2 0 "s" "SIP+D2U"       "" _sip._udp
;
;_service._proto.name   SRV     prio weight     port    target
_dns._udp               SRV     1 10            53      DNS
_dns._tcp               SRV     1 10            53      DNS
_smtp._tcp              SRV     1 10            25      POP3
_ssmtp._tls             SRV     1 10            465     SSL
_pop3._tcp              SRV     1 10            110     POP3
_pop3s._tls             SRV     1 10            995     SSL
_http._tcp              SRV     1 10            80      WWW
_https._tls             SRV     1 10            443     SSL
_ftp._tcp               SRV     1 10            21      FTP
_h323._tcp              SRV     1 10            1720    H323
_sips._tcp              SRV     1 10            5060    SIP
_sip._tcp               SRV     1 10            5060    SIP
_sip._udp               SRV     1 10            5060    SIP

The services above are generic ones. For a list of (some) of the names used for Microsoft AD compatibility, check the Samba Network Browsing HOWTO.

DNS resources