Types of resources records in zone files

A zone file stores the DNS data of a specific domain. In a zone file, a resource record defines the characteristics and properties of an entity available within the domain. There are many types of resource records. The most important types are SOA, NS, MX, A or AAAA, and CNAME.

The SOA (Start of Authority) record

It defines the global characteristics of the domain and authorizes a name server for it. It is a compulsory record. Each zone file must include one SOA record. You cannot add two or more SOA records in a zone file. You can add only one SOA record in a zone file.

It uses the following syntax.

domain-name TTL class-type record-type name-server e-mail-address serial-number refresh-time retry-time expiry-time negative-cache-TTL

The following is an example SOA record. It authorizes ns1.example.com. name server for the domain.

; The SOA (Start of Authority) record
@	IN	SOA	    ns1.example.com.	hostmaster.example.com. (
                                                            2023013100 ; serial-number
                                                            12 h; refresh-time
                                                            15 m; retry-time
                                                            3 w; expiry-time
                                                            2 h; negative-cache-TTL
                                                            )

If you use a single @ character in the domain name field, it replaces it with the domain name stored in the $ORIGIN directive.

This tutorial is the third part of the tutorial series "DNS zone files Explained with Examples.". Each tutorial of this series explains a specific aspect of the zone file. Other tutorials of the series are the following.

DNS zone file Format, Configuration, and Directives

The TTL and ORIGIN directives in the zone file

The SOA Record Explained in the DNS zone file

The NS Record, Glue Record, and Lame Delegation

The MX record in a zone file explained

The A, AAAA, and CNAME resource records

The pointer (PTR) record and Reverse mapping Explained

The NS (Name Server) record

It defines the authorized DNS servers for this domain. It is a compulsory record. There must be at least two name server records in a zone file. You can also add a reference to an external name server.

It uses the following syntax.

domain-name TTL class-type record-type authorized-name-server

The following are examples of the NS record.

; The NS records.
; Primary or main NS server. Available within the domain.
    3w	IN 	NS 	ns1.example.com.
; Secondary or backup NS server. Available outside the domain.
        IN 	NS 	ns2.example.net.

The above example NS records configure two name servers. The ns1.example.com. is the primary name server and is available within the domain. The ns2.example.net. is the secondary or backup name server. It is available outside the domain.

The MX (Mail exchanger) record

It defines the mail servers for this domain. It is an optional record. If the domain does not provide e-mail services, you do not need to add it to the zone file. You can also add a reference to an external email server.

It uses the following syntax.

domain-name TTL class-type record-type preference email-server-name

The following are examples of the MX record.

; The MX records
; Primary or main NS server. Available within the domain.
    3w 	IN 	MX 	10 	mail.example.com.
; Secondary or backup NS server. Available outside the domain.
        IN 	MX 	20 	mail.example.net.

In the above example, MX records configure two mail servers. The mail.example.com mail server is internal and is available within the domain. The mail.example.net mail server is external. It is available outside the domain.

The A (Address) record

It defines the IPv4 address of a host or a service that exists in this domain and is required to be publicly visible. It is an optional record. It uses the following syntax.

name TTL class-type record-type IPv4 address

The following are example A records.

; The A records
ns1 		IN	 A 	172.168.1.1
mail 		IN	 A 	172.168.1.2
www 		IN 	 A 	172.168.1.3

The AAAA (Quad A) record

It defines the IPv6 address of a host or a service that exists in this domain and is required to be publicly visible. It is an optional record. It uses the following syntax.

name TTL class-type record-type IPv4 address

The following are examples of AAAA records.

ns1 		IN	 AAAA 	2002:db7::
mail 		IN	 AAAA	2002:db8::
www 		IN 	 AAAA 	2002:db9::

The CNAME record

It defines an alias name of a host or a service that exists within the domain and is required to be publicly visible by the alias name.

It uses the following syntax.

alias-name TTL class-type record-type host-or-service-name

The following are example CNAME records.

; The CNAME  records
ftp 		IN 	CNAME 	fhost
www		IN 	CNAME	whost

ComputerNetworkingNotes Linux Tutorials Types of resources records in zone files