SproutDNS Help

DNS Configuration

SproutDNS uses a DNS zone configuration similar to DNS configuration for a regular authoritative DNS server; there are just two changes.

An authoritative DNS server accepts questions - a hostname and a query type - and in the simplest case it returns zero or more answers that match that question. In a regular zone file the questions and answers are fixed, and the server will respond when the hostname and query type match exactly.

example.com IN TXT 3600 "v=spf1 -all"

Here any TXT query with the hostname example.com will return a TXT record containing the string v=spf1 -all.

SproutDNS extends this functionality using regular expressions.

{ "name": "(?P<selector>[^.]+)\\._domainkey\\.(?P<customer>[^.]+)\\.example\\.com.", "ttl": "1h0m0s", "answers": { "CNAME": [ "${selector}._dkim.example.com" ] } }

With SproutDNS the "name" is a regular expression - in this example it will match any hostname that starts with any word, then "._domainkey." then any word and ".example.com". We label the first word <selector> and the second word <customer>. That lets us use the values of those words in the result.

So a query for k1._domainkey.customer_one.example.com would return a CNAME record pointing at k1._dkim.example.com.

And a query for key2._domainkey.other_customer.example.com would return a CNAME record pointing at keys._dkim.example.com.

In the json configuration file any name can be either a literal hostname or a regular expression. The regular expression will be matched against the hostnames of incoming requests.

Answers that are CNAME, TXT, NS, MX or PTR records will have anything that looks like ${variable_name} replaced with the matching word from the hostname of the query. Records of any other type will be return literally, without any variable replacement.

For clarity we suggest using this syntax, but the full Go regexp template language is supported:

In the template, a variable is denoted by a substring of the form \{name}, where name is a non-empty sequence of letters, digits, and underscores. A purely numeric name like $1 refers to the submatch with the corresponding index; other names refer to capturing parentheses named with the (?P<name>...) syntax. A reference to an out of range or unmatched index or a name that is not present in the regular expression is replaced with an empty slice.

In the 1x is equivalent to {1}x, and, {10}, not ${1}0.

To insert a literal $ in the template.

Last modified: 23 July 2024