DNS zone file Format, Configuration, and Directives

DNS saves its database in zone files. A zone file stores records of a particular domain in simple text format. It contains three types of entries: comments, directives, and resource records.

Comments

A comment starts with a semicolon (;) and continues to the end of the line. You can add a comment to any directive or record. DNS ignores everything you write after a semicolon till the next line. If you put a semicolon at the beginning of a line, DNS ignores the entire line. If you put a semicolon in the middle of the line, DNS ignores everything that comes after the semicolon.

The followings are examples of comments.

; This line starts with a semicolon. DNS will not read it. It is an example of a full-line comment.
$TTL 12h; DNS will not read this line after the semicolon (;).

Directives

A directive starts with a dollar sign. It works as a variable. It stores value. DNS replaces a directive with its value when it processes the zone file. There are two important directives $TTL and $ORIGIN.

$TTL

This directive is mandatory. It defines the default Time to Live (TTL) value for resource records.

$ORIGIN

This directive defines the domain or zone name. The domain or zone name must end with a dot. This directive is optional. It allows you to use relative names in the file.

FQDN and Relative names

In the DNS database, a resource's name can be either an FQDN name or a relative name.

An FQDN (fully qualified domain name) name is a complete name. It includes the names of all top-level domains till the root domain. It ends with a dot. You can access a resource from anywhere in the domain system using its FQDN name. The following are examples of FQDN names.

ca.north.example.co.us., wa.south.example.co.us., la.east.example.co.us. ny.west.example.co.us.

A relative name is a hostname. It may or may not include the parent domain's name. It does not end with a dot. In the DNS system, you cannot access a resource from outside the domain using its relative name. However, you can access a resource inside the domain using its relative name. The following are examples of relative names.

ca.north, wa.south, la.east, ny.west

You can use both types of names in the zone file, but DNS will process only FQDN names. If you use a relative name in the zone file, DNS automatically converts it into the FQDN name before processing it.

To convert a relative name into the FQDN name, it uses the $ORIGIN directive's value. The $ORIGIN directive stores the FQDN name of the domain. It attaches the domain's FQDN name to the relative name as a suffix to make it the FQDN name. Let's take an example. If the relative name is ca.north and the $ORIGIN directive has the value example.com., then the FQDN name will be ca.north.example.com. (ca.north + example.com.).

Resources records

A resource record defines the characteristics and properties of an entity within the domain. There are many types of resource records. The most important resource record types are SOA, NS, MX, A, AAAA, and PTR.

Formatting records

A zone file uses lines to store resource records. For each record, it uses a separate line. If you want to create a record in multiple lines, you need to use a parenthesis. DNS process everything you put between an opening parenthesis and a closing parenthesis as a part of the line. Administrators use this feature to make the SOA record more human-readable. The following image shows an example SOA record.

example soa record

DNS will see the above example SOA record as the following.

@ IN SOA ns1.example.com. hostmaster.example.com.    2023013100   12h   15m   3w  2h

To separate two fields in a record, you can use either spaces or tabs. Generally, tabs are used for it. Tabs provide a more attractive layout and clearly indicate the added and missed fields.

The following records use blank spaces as separators.

using space

If we use tab spaces as separators, the above records will look like the following.

using tabs

As we can see in the above records, if we use tabs to separate the fields in the records, the fields look neat and descriptive. We can easily identify which fields have values and which fields are empty.

The following example zone file summarizes all the topics mentioned above.

example zone file

That's all for this tutorial. This tutorial is the first 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.

ComputerNetworkingNotes Linux Tutorials DNS zone file Format, Configuration, and Directives