Examples

Typical DNS Records

dnsconfig.js
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
    A("@", "1.2.3.4"),  // The naked or "apex" domain.
    A("server1", "2.3.4.5"),
    AAAA("wide", "2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
    CNAME("www", "server1"),
    CNAME("another", "service.mycloud.com."),
    MX("mail", 10, "mailserver"),
    MX("mail", 20, "mailqueue"),
    TXT("the", "message"),
    NS("department2", "ns1.dnsexample.com."), // use different nameservers
    NS("department2", "ns2.dnsexample.com."), // for department2.example.com
);

Set TTLs

dnsconfig.js
var mailTTL = TTL("1h");

D("example.com", REG_MY_PROVIDER,
    NAMESERVER_TTL("10m"), // On domain apex NS RRs
    DefaultTTL("5m"), // Default for a domain

    MX("@", 5, "1.2.3.4", mailTTL), // use variable to
    MX("@", 10, "4.3.2.1", mailTTL), // set TTL

    A("@", "1.2.3.4", TTL("10m")), // individual record
    CNAME("mail", "mx01"), // TTL of 5m, as defined per DefaultTTL()
);

Variables for common IP Addresses

NOTE: The IP() function doesn't currently support IPv6 (PRs welcome!). IPv6 addresses are strings.

Variables to swap active Data Center

Macro for repeated records

Use SPF_BUILDER to add comments to SPF records

Set default records modifiers

Advanced Examples

Dual DNS Providers

Automate Fastmail DKIM records

In this example we need a macro that can dynamically change for each domain.

Suppose you have many domains that use Fastmail as an MX. Here's a macro that sets the MX records.

Fastmail also supplied CNAMES to implement DKIM, and they all match a pattern that includes the domain name. We can't use a simple macro. Instead, we use a function that takes the domain name as a parameter to generate the right records dynamically.

We can then use the macros as such:

More advanced examples

See the Code Tricks page.

Last updated