Default zonefile

# Default zonefiles

Default zonefiles are useful when one has a large number of identical zones. They are also useful for setups like "have all records resolve to a given IP address", for example when setting up connections to the internet that require authentication to use, and want all traffic to be directed to a web page stating "you're not logged in to use the internet yet".

A default zonefile is a CSV2 zone file where stars can be at the end of hostnames. There are a few restrictions with default zone files:

- A SOA record is mandatory
- NS records are mandatory
- Neither CNAME nor FQDN4 records are permitted in the zone file
- Delegation NS records are not permitted in the zone file
- Default zonefiles may not be transferred via zone transfer

It also is not possible to run recursion on a server that uses a default zonefile. With the exception of these restrictions, and the ability to have a '*' at the end of a hostname (or simply the catch-all wildcard hostname '*'), a csv2 default zone file functions like a normal csv2 zone file.

A default zone file looks like this:

    # This is an example csv2_default_zonefile

    *       SOA     example.com. email@example.com. 1 7200 3600 604800 1800

    *       NS      a.example.com.
    *       NS      b.example.com.

    # Here are some A (ipv4 address) records; since this is the most
    # common field, the zone file format allows a compact representation
    # of it.

    * 10.10.10.10

    # The A record can be specified explicitly, but doesn't need to be
    # E.g. the above line could have been written '* A 10.10.10.10'
    www.* A 10.10.10.10

    # Here is a MX record
    * MX 10 mail.example.com.

Here, "example.com" is replaced with the name of the zone server running MaraDNS, "a.example.com." and "b.example.com." replaced with the NS entries running MaraDNS, 10.10.10.10 is replaced with the IP for the machine in question, and "mail.example.com." is replaced with the name of the machine that accepts mail for this domain.

NS entries are the names of machines which are running this instance of MaraDNS. In the above example, we will also have an "example.com" zone that will have "a.example.com" and "b.example.com" entries. The example.com domain will also have an "example.com" entry and a "mail.example.com" entry.

What this does is allow people to serve a large number of domains with MaraDNS without using up too much memory, and without needing to load a large number of domains when starting MaraDNS. The only caveat is that all of the domains need to be identical. This is often the case with large web serving farms. In situations where different domains are served by different machines in the web serving farm, one simply runs multiple instances of MaraDNS on different IPs; machines hosted on different machines just use different DNS servers. Since MaraDNS is a small program, suitable for embedded applications, even running multiple instances of MaraDNS will be more lightweight than running other DNS servers when there are a large number of domains and only a few web servers processing the domains.

## Record searching order

When the default zonefile is enabled, MaraDNS searches for records in the following order:

- MaraDNS first searches for any non-wildcard records in non-default zone files.
- MaraDNS then searches for wildcard records in non-default zone files (records with a star at the beginning of them).
- Should no records be found, MaraDNS then looks for records with stars at the end of them. MaraDNS does this by removing the final field from a domain name until a match is found. For example, if someone sends MaraDNS a request for "www.mx.example.com", we will first look for "www.mx.example.*" in the default zone file, followed by looking for "www.mx.*", followed by "www.*", and finally "*".