Master File Format in DNS

The DNS Master File, also known as a zone file, is a text file that describes a DNS zone. This file contains mappings between domain names and IP addresses, along with other resources, structured according to specific formatting rules. The master file is crucial for the functioning of DNS servers as it helps in translating domain names to IP addresses and other resources necessary for network operations.

Structure and Syntax

A master file consists of a series of resource records (RRs) in text form. Each line in the file corresponds to a single resource record. The general format of a resource record in a master file is:

[<name>] [<TTL>] [<class>] <type> <RDATA>
  • name: The domain name, relative to the origin.

  • TTL (Time to Live): Optional field specifying the duration in seconds for which the record may be cached.

  • class: The class of the data, typically IN for Internet.

  • type: The type of the record (e.g., A, MX, CNAME).

  • RDATA: The resource data specific to the type of the record.

Common Resource Record Types

  1. A (Address Record): Maps a domain name to an IPv4 address.

    example.com. 3600 IN A 93.184.216.34
  2. AAAA (IPv6 Address Record): Maps a domain name to an IPv6 address.

    example.com. 3600 IN AAAA 2606:2800:220:1:248:1893:25c8:1946
  3. CNAME (Canonical Name Record): Maps an alias domain name to a canonical domain name.

    www.example.com. 3600 IN CNAME example.com.
  4. MX (Mail Exchange Record): Specifies mail servers for a domain.

    example.com. 3600 IN MX 10 mail.example.com.
  5. NS (Name Server Record): Specifies authoritative name servers for a domain.

    example.com. 3600 IN NS ns1.example.com.
  6. PTR (Pointer Record): Used for reverse DNS lookups.

    34.216.184.93.in-addr.arpa. 3600 IN PTR example.com.
  7. SOA (Start of Authority Record): Provides information about the DNS zone.

    example.com. 3600 IN SOA ns1.example.com. admin.example.com. (
        2021071501 ; Serial
        3600       ; Refresh
        1800       ; Retry
        1209600    ; Expire
        3600       ; Minimum TTL
    )
  8. TXT (Text Record): Holds arbitrary text data, often used for SPF records.

    example.com. 3600 IN TXT "v=spf1 include:_spf.example.com ~all"

Comments

Comments in a master file start with a semicolon (;) and continue to the end of the line. They are ignored by DNS servers.

; This is a comment
example.com. 3600 IN A 93.184.216.34

Example of a Complete Zone File

Below is an example of a complete zone file for example.com:

$TTL 3600
@       IN      SOA     ns1.example.com. admin.example.com. (
                        2021071501 ; Serial
                        3600       ; Refresh
                        1800       ; Retry
                        1209600    ; Expire
                        3600       ; Minimum TTL
                        )

        IN      NS      ns1.example.com.
        IN      NS      ns2.example.com.

        IN      MX      10 mail.example.com.

        IN      A       93.184.216.34
www     IN      CNAME   example.com.
mail    IN      A       93.184.216.35

Special Syntax

  • $ORIGIN: Sets the domain name origin for relative names.

  • $TTL: Sets the default TTL for records without an explicit TTL.

Example using $ORIGIN:

$ORIGIN example.com.
@       IN      A       93.184.216.34
www     IN      CNAME   example.com.

Conclusion

The master file format is essential for defining the structure and behavior of a DNS zone. Understanding this format is critical for anyone involved in DNS management, as it ensures proper resolution of domain names and efficient management of network resources.

Last updated