Zone file
A Domain Name System zone file is a text file that describes a DNS zone. A DNS zone is a subset, often a single domain, of the hierarchical domain name structure of the DNS. The zone file contains mappings between domain names and IP addresses and other resources, organized in the form of text representations of resource records. A zone file may be either a DNS master file, authoritatively describing a zone, or it may be used to list the contents of a DNS cache.
File format
The format of a zone file is defined in and . This format was originally used by the Berkeley Internet Name Domain software package, but has been widely adopted by other DNS server software – though some of them are using the zone files only as a starting point to compile them into database format, see also Microsoft DNS with Active Directory-database integration.A zone file is a sequence of line-oriented entries, each of which is either a directive or a text description that defines a single resource record. An entry is composed of fields separated by any combination of white space, and ends at a line boundary except inside a quoted string field value or a pair of enclosing formatting parentheses. Any line may end with comment text preceded by a semicolon, and the file may also contain any number of blank lines.
Entries may occur in any order in a zone file with an exception that SOA record must be at top of the zone.
Directives are control entries that affect the rest of the zone file. The first field of a directive consists of a dollar sign followed by a keyword:
- $ORIGIN is followed by a domain name to be used as the origin for subsequent relative domain names.
- $INCLUDE is followed by a file name and optional origin domain name to be used when interpreting its contents.
- $TTL, defined in , is followed by a number to be used as the default TTL (time-to-live).
- $GENERATE, a non-standard extension accepted by BIND and some other name server software to insert multiple resource records with one entry, is followed by a concise representation of an increasing sequence of nonnegative numbers and then a template RR entry. A resource record is added for each number in the sequence, using the template with unescaped "$" characters replaced by the number.
The name field may be left blank. If so, the record inherits the field from the previous record. A free standing @ is used to denote the current origin.
The ttl field specifies the number of seconds after which a caching client must discard the record and perform a new resolution operation to obtain fresh information. Some name servers, including BIND, allow nonstandard representations that use time unit abbreviations. It may be omitted, in which case the resulting value will be set from the default TTL or from the preceding record.
The record class field indicates the namespace of the record information. It may be omitted, in which case the resulting value will be set from the preceding record. The most commonly used namespace is that of the Internet, indicated by parameter IN, but others exist and are in use, e.g., CHAOS.
The record type field is an abbreviation for the type of information stored in the last field, record data. For example: an address record maps the domain name from the first field to an IP address in the record data; a mail exchanger record specifies the Simple Mail Transfer Protocol mail host for a domain.
The record data field may consist of one or more information elements, depending on the requirements of each record type. For example, an address record only requires an address, while a mail exchanger record requires a priority and a domain name. Such information elements are represented as fields separated by white space.
Example file
An example of a zone file for the domain example.com is the following:At minimum, the zone file must specify the Start of Authority record with the name of the authoritative master name server for the zone and the email address of someone responsible for management of the name server. The parameters of the SOA record also specify a list of timing and expiration parameters. Some name servers, including BIND, also require at least one additional NS record.
In the zone file, domain names that end with a full stop character are fully qualified while those that do not end with a full stop are relative to the current origin.
A zone file is referenced by the configuration file of the name server software. For example, BIND typically uses a statement such as:
zone "example.com" ;
Root zone and top-level domains
The zone files for the DNS root zone and for the set of top-level domains contain resource records only for the authoritative domain name servers for each domain name.Localhost
Some server software automatically configures resource records for specially recognized domains or hostnames, such as localhost, but a customized zone master file may be used.An example for manual configuration of the forward zone for localhost is the following:
$ORIGIN localhost.
@ 86400 IN SOA @ root
900 ; retry
604800 ; expire
86400 ; minimum
)
@ 86400 IN NS @
@ 86400 IN A 127.0.0.1
@ 86400 IN AAAA ::1
The corresponding reverse zone definition is:
;; reverse zone file for 127.0.0.1 and ::1
$TTL 1814400 ; 3 weeks
@ 1814400 IN SOA localhost. root.localhost.
900 ; retry
604800 ; expire
86400 ; minimum
)
@ 1814400 IN NS localhost.
1 1814400 IN PTR localhost.
This file does not specify the origin so that it may be used for both IPv4 and IPv6 with this configuration:
zone "0.0.127.in-addr.arpa" IN ;
zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN ;
Similar zone master files may be created for the reverse resolution of the broadcast address and the null address. Such zone files prevent a DNS server from referring to other, possibly external DNS servers.