Managing DNS with DNSControl
Published · UpdatedDNSControl lets you describe DNS records in code and review changes before applying them. Keep the configuration in Git so changes can be reviewed alongside the applications that depend on them.
Try a local zone first
Install DNSControl using the official installation instructions. Create a working directory with a zones subdirectory, then save this as dnsconfig.js:
var registrar = NewRegistrar("none");
var localDns = NewDnsProvider("bind");
D("example.com", registrar, DnsProvider(localDns),
A("@", "192.0.2.10"),
CNAME("www", "example.com.")
);
Create creds.json alongside it:
{
"bind": {
"TYPE": "BIND"
}
}
This uses the BIND provider to write a local zone file. It does not change public DNS. The address is for documentation; replace it for a real deployment.
Preview and apply
mkdir -p zones
dnscontrol preview
Review the proposed records. To write the local zone file:
dnscontrol push
Change the address in dnsconfig.js and preview again to see the difference.
Connect a DNS provider
DNS records belong in dnsconfig.js; provider credentials belong in creds.json. Follow your provider’s configuration documentation and keep secrets out of Git.
For an existing domain, first reproduce its current records. Review the entire preview before pushing: switching to a live provider makes push change real DNS, including proposed deletions. Preserve mail and verification records as well as application addresses.