The short answer

Write your zones in dnsconfig.js, keep provider credentials in creds.json (read from environment variables, never committed with secrets), import existing zones with dnscontrol get-zones, and change DNS only with dnscontrol preview followed by dnscontrol push. DNSControl makes the provider match the file exactly, deleting records that are not in it, so tell it which records other systems own before the first push.

A worked example

dnsconfig.js:

var REG_NONE = NewRegistrar("none");
var DSP_MAIN = NewDnsProvider("dns_main");

D("example.com", REG_NONE, DnsProvider(DSP_MAIN),
    DefaultTTL(3600),
    A("@", "192.0.2.10"),
    CNAME("www", "example.com."),
    A("mail", "192.0.2.25"),
    MX("@", 10, "mail"),
    TXT("@", "v=spf1 mx -all"),
    TXT("_dmarc", "v=DMARC1; p=quarantine; rua=mailto:[email protected]"),
    CAA("@", "issue", "letsencrypt.org"),
    IGNORE("_acme-challenge", "TXT"),
    IGNORE("_acme-challenge.**", "TXT")
);

creds.json, with secrets taken from the environment:

{
  "none": { "TYPE": "NONE" },
  "dns_main": {
    "TYPE": "CLOUDFLAREAPI",
    "apitoken": "$CLOUDFLARE_API_TOKEN"
  }
}
PartWhat it does
NewRegistrar("none")DNSControl will not touch the registrar. Use a real registrar provider only if you want it to manage the delegation too.
NewDnsProvider("dns_main")Points at the dns_main entry in creds.json. Changing provider means changing that entry.
Relative names"@" is the apex and "mail" means mail.example.com.; full names need the trailing dot
IGNORE(...)Leaves records owned by something else, here an ACME client, alone. The second rule covers challenges for subdomains, such as _acme-challenge.www.

Day-to-day commands

CommandWhat it does
dnscontrol checkValidates dnsconfig.js without contacting any provider
dnscontrol previewLists the creates, changes and deletes needed to make each provider match the file. Changes nothing.
dnscontrol pushMakes those changes
dnscontrol preview --domains example.comLimits the run to one zone

Run preview in review (for example on every pull request) and push only after the change is approved. See safe DNS changes in CI/CD.

Importing an existing zone

  1. Export the current records as the starting configuration, and keep a copy of the output; it is also your rollback.
    CommandWhat it does
    dnscontrol get-zones --format=js dns_main - example.comPrints a D() block for the zone, using the dns_main entry in creds.json
  2. Tidy it: use relative names, a DefaultTTL, and remove records you know are obsolete in a separate, later change.
  3. Add IGNORE rules for anything managed elsewhere: ACME challenges, Kubernetes ExternalDNS records, provider verification records you do not want in code.
  4. Run dnscontrol preview until it reports no changes. Only then is the file a true description of the zone.
  5. Make the first real change small, such as one TTL.

If you are not ready to let DNSControl delete anything, NO_PURGE in the D() block makes it add and change records but never remove them. Remove it once the zone is fully described.

Using more than one provider

Listing two providers serves the same records from both, which is how many teams run multi-provider DNS:

D("example.com", REG_NONE,
    DnsProvider(DSP_MAIN),
    DnsProvider(DSP_SECOND),
    A("@", "192.0.2.10")
);
  • Every record must be supported by both providers. dnscontrol check and preview report types a provider cannot hold.
  • Provider-specific features do not travel: proxying, provider alias records and traffic steering exist on one provider only, so the two answers can differ.
  • NS records are combined from both providers by default. Make sure the registrar delegation lists the same set.
  • DNSSEC with two signing providers needs both providers' keys published, which few providers support. Many multi-provider setups use one signer and zone transfers instead.

Reviewing changes and recovering

  • Read the preview for DELETE lines first. A record missing from the file is a record DNSControl will remove.
  • Change TTLs and values in separate pushes when the change matters, as in planning a DNS change.
  • To roll back, revert the commit and push again. Keep the get-zones export from before a big change in case the file itself was wrong.
  • Run preview on a schedule to catch drift from dashboard edits, and decide whether to adopt or revert each one.

How DNS Panopticon helps

DNS Panopticon does not read dnsconfig.js or push changes. After a push, the DNS Propagation Checker shows whether each provider's nameservers serve the new record, and Security Posture checks the result, including the email records and CAA in the example above.

FAQ

Will DNSControl delete records that are not in my file?

Yes, by default it makes the provider match the file exactly. Use IGNORE for records owned by other systems, or NO_PURGE while you are still importing.

Do I need to change my registrar to use DNSControl?

No. Use the NONE registrar and DNSControl only manages records at your DNS provider. The delegation at the registrar stays as it is.

Can DNSControl move a zone to a new provider?

Yes. Add the new provider, push so both serve the same records, change the delegation at the registrar, wait for the parent NS TTL, then remove the old provider.

Is preview safe to run against production?

Yes. It only reads from the providers and prints the changes it would make.

Sources and further reading