Zone File Format
The native DNS zone file format of SproutDNS is json-based. It is a json object that one entry for each DNS zone being served. The key is a string containing the zone name, e.g. "example.com"
, and the value is an array of records.
Each record is a json object with three values:
name
- the literal hostname or a regular expression to match a hostname.ttl
- a string containing an integer number of seconds, or a sequence of decimal numbers and units. Useful time units are "h", "m" or "s".answers
- an object containing the DNS answers
When answering a query SproutDNS will first identify which zone the answer is in, then it will check each answer record in that zone in order until one matches the hostname of the request. That answer object will be used and no further ones are checked.
The answers object contains zero or more entries. For each the key is a string containing the DNS type of the response, e.g. "MX" or "CNAME", and the value is an array of strings. Each string will be converted into one resource record in the answer section of the DNS response.
Each string in the answer contains the record answer in bind format, e.g. an A record might be "10.11.12.13"
, an MX record might be "10 mail.example.com"
.
TXT records must be formatted with double quotes around the value, and those must be escaped in the json, so it may look like "\\"v=spf1 -all\\""
. If the value of a TXT record is too long, after any value replacements, it will be split into multiple strings.
Each zone must contain an SOA record.
Escaping
As mentioned above answers must be escaped if they include double quotes.
Names are more complex. If the value of a "name" is just a hostname then it will be treated as a literal string and nothing needs to be escaped.
If it doesn't look like a hostname (has any characters that aren't alphameric, underscore or dot) it will be treated as a regular expression. This leads to two levels of escaping, regular expression and json. The main implication of this is that to match a dot a string like "\\."
or "[.]"
is needed.
A bare dot - "." - will match any single character. It will match the dot in a hostname, but also any other character. So "(?P<name>foo).example.com"
will match the hostname foo.example.com
but will also match foomexample.com
.
Common phrases
To match any word in a hostname - i.e. any series of characters not containing a dot - you can use [^.]+
.
To match any word in a hostname and capture the value for use in the result you can use (?P<name>[^.]+)
.
You can see these in use in the sample zone file.
Bind style zone files
SproutDNS can convert bind style zone files to this json format, see here.