2017-09-30 03:44:13 +08:00
|
|
|
---
|
|
|
|
layout: default
|
2017-10-11 20:33:17 +08:00
|
|
|
title: Migrating zones to DNSControl
|
2017-09-30 03:44:13 +08:00
|
|
|
---
|
|
|
|
|
2017-04-14 00:46:47 +08:00
|
|
|
# Migrating zones to DNSControl
|
|
|
|
|
|
|
|
This document explains how to migrate (convert) DNS zones from
|
|
|
|
other systems to DNSControl's `dnsconfig.js` file.
|
|
|
|
|
|
|
|
This document assumes you have DNSControl set up and working on at
|
|
|
|
least one zone. You should have a working `dnsconfig.js` file and
|
|
|
|
`creds.json` file as explained in the
|
|
|
|
[Getting Started]({{site.github.url}}/getting-started) doc.
|
|
|
|
|
|
|
|
## General advice
|
|
|
|
|
2017-08-30 01:49:39 +08:00
|
|
|
First, use the
|
2017-04-14 00:46:47 +08:00
|
|
|
[Getting Started]({{site.github.url}}/getting-started) doc
|
|
|
|
so that you have a working `dnsconfig.js` with at least one domain.
|
|
|
|
|
|
|
|
We recommend migrating one zone at a time. Start with a small,
|
|
|
|
non-critical, zone first to learn the process. Convert larger,
|
|
|
|
more important, zones as you gain confidence.
|
|
|
|
|
|
|
|
Experience has taught us that the best way to migrate a zone is
|
|
|
|
to create an exact duplicate first. That is, convert the old DNS records
|
|
|
|
with no changes. It is tempting to clean up the data as you do the migration...
|
2017-08-05 23:59:35 +08:00
|
|
|
removing that old CNAME that nobody uses any more, or adding an
|
|
|
|
A record you discovered was missing. Resist that temptation. If you make any
|
2017-04-14 00:46:47 +08:00
|
|
|
changes it will be difficult to tell which changes were intentional
|
2018-02-28 06:36:47 +08:00
|
|
|
and which are mistakes. During the migration you will know you are done
|
|
|
|
when `dnscontrol preview` says there are no changes needed. At that
|
|
|
|
point it is safe to do any cleanups.
|
2017-04-14 00:46:47 +08:00
|
|
|
|
|
|
|
## Create the first draft
|
|
|
|
|
|
|
|
Create the first draft of the `D()` statement either manually or
|
|
|
|
automatically.
|
|
|
|
|
|
|
|
For a small domain you can probably create the `D()` statements by
|
|
|
|
hand, possibly with your text editor's search and replace functions.
|
|
|
|
However, where's the fun in that?
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
The `dnscontrol get-zones` subcommand
|
|
|
|
[documented here]({{site.github.url}}/get-zones)
|
2020-06-18 21:37:09 +08:00
|
|
|
can automate 90% of the conversion for you. It reads BIND-style zonefiles,
|
|
|
|
or will use a providers API to gather the DNS records. It will then output
|
|
|
|
the records in a variety of formats, including as a `D()` statement
|
2020-02-18 21:59:18 +08:00
|
|
|
that is usually fairly complete. You may need to touch it up a bit,
|
|
|
|
especially if you use pseudo record types in one provider that are
|
|
|
|
not supported by another.
|
2017-04-14 00:46:47 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
Example 1: Read a BIND zonefile
|
2017-04-14 00:46:47 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
Most DNS Service Providers have an 'export to zonefile' feature.
|
2017-04-14 00:46:47 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
```
|
2020-06-18 21:37:09 +08:00
|
|
|
dnscontrol get-zones --format=js bind BIND example.com
|
|
|
|
dnscontrol get-zones --format=js --out=draft.js bind BIND example.com
|
2020-02-18 21:59:18 +08:00
|
|
|
```
|
2017-04-14 00:46:47 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
This will read the file `zones/example.com.zone`. The system is a bit
|
2020-06-18 21:37:09 +08:00
|
|
|
inflexible and that must be the filename. You can copy the zone file to
|
|
|
|
that name or use a symlink.
|
2018-02-28 06:36:47 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
Add the contents of `draft.js` to `dnsconfig.js` and edit it as needed.
|
2018-02-28 06:36:47 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
Example 2: Read from a provider
|
2017-04-14 00:46:47 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
This requires creating a `creds.json` file as described in
|
|
|
|
[Getting Started]({{site.github.url}}/getting-started).
|
|
|
|
|
|
|
|
Suppose your `creds.json` file has the name `global_aws`
|
|
|
|
for the provider `ROUTE53`. Your command would look like this:
|
|
|
|
|
|
|
|
```
|
2020-06-18 21:37:09 +08:00
|
|
|
dnscontrol get-zones --format=js global_aws ROUTE53 example.com
|
|
|
|
dnscontrol get-zones --format=js --out=draft.js global_aws ROUTE53 example.com
|
2020-02-18 21:59:18 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
Add the contents of `draft.js` to `dnsconfig.js` and edit it as needed.
|
2017-04-14 00:46:47 +08:00
|
|
|
|
2018-02-28 06:36:47 +08:00
|
|
|
Run `dnscontrol preview` and see if it finds any differences.
|
2017-04-14 00:46:47 +08:00
|
|
|
Edit dnsconfig.js until `dnscontrol preview` shows no errors and
|
|
|
|
no changes to be made. This means the conversion of your old DNS
|
|
|
|
data is correct.
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
`dnscontrol get-zones` makes a guess at what to do with NS records.
|
2018-02-28 06:36:47 +08:00
|
|
|
An NS record at the apex is turned into a NAMESERVER() call, the
|
2017-08-05 23:59:35 +08:00
|
|
|
rest are left as NS(). You probably want to check each of them for
|
|
|
|
correctness.
|
|
|
|
|
2017-04-14 00:46:47 +08:00
|
|
|
Resist the temptation to clean up and old, obsolete, records or to
|
|
|
|
add anything new. Experience has shown that making changes at this
|
|
|
|
time leads to unhappy surprises, and people will blame DNSControl.
|
|
|
|
Of course, once `dnscontrol preview` runs cleanly, you can do any
|
|
|
|
kind of cleanups you want. In fact, they should be easier to do
|
|
|
|
now that you are using DNSControl!
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
If `dnscontrol get-zones` could have done a better job, please
|
2017-04-14 00:46:47 +08:00
|
|
|
[let us know](https://github.com/StackExchange/dnscontrol/issues)!
|
|
|
|
|
|
|
|
## Example workflow
|
|
|
|
|
|
|
|
Here is an example series of commands that would be used
|
|
|
|
to convert a zone. Lines that start with `#` are comments.
|
|
|
|
|
|
|
|
# Note this command uses ">>" to append to dnsconfig.js. Do
|
|
|
|
# not use ">" as that will erase the existing file.
|
2020-06-18 21:37:09 +08:00
|
|
|
dnscontrol get-zones --format=js --out=draft.js bind BIND foo.com
|
2020-02-18 21:59:18 +08:00
|
|
|
cat >>dnsconfig.js draft.js # Append to dnsconfig.js
|
2017-04-14 00:46:47 +08:00
|
|
|
#
|
|
|
|
dnscontrol preview
|
|
|
|
vim dnsconfig.js
|
|
|
|
# (repeat these two commands until all warnings/errors are resolved)
|
|
|
|
#
|
|
|
|
# When everything is as you wish, push the changes live:
|
|
|
|
dnscontrol push
|
|
|
|
# (this should be a no-op)
|
|
|
|
#
|
|
|
|
# Make any changes you do desire:
|
|
|
|
vim dnsconfig.js
|
|
|
|
dnscontrol preview
|
|
|
|
# (repeat until all warnings/errors are resolved)
|
2020-02-18 21:59:18 +08:00
|
|
|
dnscontrol push
|