2017-01-12 04:02:45 +08:00
# Getting Started
2017-05-02 21:08:28 +08:00
## 1. Install the software
2017-01-12 04:02:45 +08:00
2022-11-02 03:13:53 +08:00
Choose one of the following installation methods:
2017-01-12 04:02:45 +08:00
2022-11-02 03:13:53 +08:00
### Homebrew
2017-01-12 04:02:45 +08:00
2022-11-02 03:13:53 +08:00
On macOS (or Linux) you can install it using [Homebrew ](https://brew.sh ).
2020-11-19 05:15:18 +08:00
2023-01-20 20:56:20 +08:00
```shell
2022-11-02 03:13:53 +08:00
brew install dnscontrol
```
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
### MacPorts
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
Alternatively on macOS you can install it using [MacPorts ](https://www.macports.org ).
2020-11-19 05:15:18 +08:00
2023-01-20 20:56:20 +08:00
```shell
2022-11-02 03:13:53 +08:00
sudo port install dnscontrol
2023-01-13 05:59:42 +08:00
```
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
### Docker
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
You can use DNSControl locally using the Docker image from [Docker hub ](https://hub.docker.com/r/stackexchange/dnscontrol/ ) and the command below.
2020-11-19 05:15:18 +08:00
2023-01-20 20:56:20 +08:00
```shell
2022-11-02 03:13:53 +08:00
docker run --rm -it -v $(pwd)/dnsconfig.js:/dns/dnsconfig.js -v $(pwd)/creds.json:/dns/creds.json stackexchange/dnscontrol preview
```
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
### Binaries
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
Download binaries from [GitHub ](https://github.com/StackExchange/dnscontrol/releases/latest ) for Linux (binary, tar, RPM, DEB), FreeBSD (tar), Windows (exec, ZIP) for 32-bit, 64-bit, and ARM.
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
### Source
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
DNSControl can be built from source with Go version 1.18 or higher.
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
The `go install` command will download the source, compile it, and
install `dnscontrol` in your `$GOBIN` directory.
2020-11-19 05:15:18 +08:00
2022-11-02 03:13:53 +08:00
To install, simply run
2017-05-02 21:08:28 +08:00
2023-01-20 20:56:20 +08:00
```shell
go install github.com/StackExchange/dnscontrol/v3@latest
```
2022-11-02 03:13:53 +08:00
To download the source
2023-01-20 20:56:20 +08:00
```shell
git clone https://github.com/StackExchange/dnscontrol
```
2022-11-02 03:13:53 +08:00
If these don't work, more info is in [#805 ](https://github.com/StackExchange/dnscontrol/issues/805 ).
2017-05-02 21:08:28 +08:00
2022-11-01 06:09:43 +08:00
## 2. Create a place for the config files
2017-05-02 21:08:28 +08:00
Create a directory where you'll be storing your configuration files.
We highly recommend storing these files in a Git repo, but for
2017-10-31 20:52:04 +08:00
simple tests anything will do.
2017-05-02 21:08:28 +08:00
Create a subdirectory called `zones` in the same directory as the
configuration files. (`mkdir zones`). `zones` is where the BIND
2018-02-28 06:36:47 +08:00
provider writes the zonefiles it creates. Even if you don't
2022-10-29 03:14:28 +08:00
use BIND for DNS service, it is useful for testing.
2017-05-02 21:08:28 +08:00
## 3. Create the initial `dnsconfig.js`
`dnsconfig.js` is the main configuration and defines providers, DNS
domains, and so on.
Start your `dnsconfig.js` file by downloading
2023-01-22 06:26:04 +08:00
[dnsconfig.js ](https://github.com/StackExchange/dnscontrol/blob/master/documentation/assets/getting-started/dnsconfig.js )
2017-05-02 21:08:28 +08:00
and renaming it.
The file looks like:
2017-01-12 04:02:45 +08:00
2023-01-20 20:56:20 +08:00
```javascript
2017-05-02 21:08:28 +08:00
// Providers:
2022-05-09 02:23:45 +08:00
var REG_NONE = NewRegistrar('none'); // No registrar.
var DNS_BIND = NewDnsProvider('bind'); // ISC BIND.
2017-05-02 21:08:28 +08:00
// Domains:
D('example.com', REG_NONE, DnsProvider(DNS_BIND),
A('@', '1.2.3.4')
2017-01-12 04:02:45 +08:00
);
2022-02-18 01:22:31 +08:00
```
2017-01-12 04:02:45 +08:00
2023-01-20 20:56:20 +08:00
Modify this file to match your particular providers and domains. See [the DNSConfig docs ](js.md ) and [the provider docs ](providers.md ) for more details.
2017-05-03 04:22:51 +08:00
2022-05-09 02:23:45 +08:00
Create a file called `creds.json` for storing provider configurations (API tokens and other account information).
For example, to use both name.com and Cloudflare, you would have:
```json
2017-05-03 04:22:51 +08:00
{
2022-05-09 02:23:45 +08:00
"cloudflare": { // The provider name used in dnsconfig.js
"TYPE": "CLOUDFLAREAPI", // The provider type identifier
"accountid": "your-cloudflare-account-id", // credentials
"apitoken": "your-cloudflare-api-token" // credentials
2017-05-03 04:22:51 +08:00
},
2022-05-09 02:23:45 +08:00
"namecom": { // The provider name used in dnsconfig.js
"TYPE": "NAMEDOTCOM", // The provider type identifier
"apikey": "key", // credentials
"apiuser": "username" // credentials
},
"none": { "TYPE": "NONE" } // The no-op provider
2017-05-03 04:22:51 +08:00
}
2022-02-18 01:22:31 +08:00
```
2017-05-03 04:22:51 +08:00
2022-11-01 06:09:43 +08:00
Note: Do **not** store your `creds.json` file in Git unencrypted.
2022-05-09 02:23:45 +08:00
That is unsafe. Add `creds.json` to your
`.gitignore` file as a precaution. This file should be encrypted
using something
like [git-crypt ](https://www.agwa.name/projects/git-crypt ) or
[Blackbox ](https://github.com/StackExchange/blackbox ).
2017-05-02 21:08:28 +08:00
There are 2 types of providers:
A "Registrar" is who you register the domain with. Start with
2022-05-09 02:23:45 +08:00
`NONE` , which is a provider that never talks to or updates the
2017-05-02 21:08:28 +08:00
registrar. You can define your registrar later when you want to
use advanced features.
2022-05-09 02:23:45 +08:00
A "DnsProvider" is the service that actually provides DNS service
(port 53) and may be the same or different as the registrar. Even if both
2017-05-02 21:08:28 +08:00
your Registrar and DnsProvider are the same company, two different
2019-05-12 09:32:52 +08:00
definitions must be included in `dnsconfig.js` .
2017-05-02 21:08:28 +08:00
## 4. Create the initial `creds.json`
`creds.json` stores credentials and a few global settings.
It is only needed if any providers require credentials (API keys,
usernames, passwords, etc.).
Start your `creds.json` file by downloading
2023-01-22 06:26:04 +08:00
[creds.json ](https://github.com/StackExchange/dnscontrol/blob/master/documentation/assets/getting-started/creds.json )
2017-05-02 21:08:28 +08:00
and renaming it.
The file looks like:
2023-01-20 20:56:20 +08:00
```json
2017-05-02 21:08:28 +08:00
{
"bind": {
2022-05-09 02:23:45 +08:00
"TYPE": "BIND"
2017-05-02 21:08:28 +08:00
},
2022-05-09 02:23:45 +08:00
"r53_accountname": {
"TYPE": "ROUTE53",
2017-05-02 21:08:28 +08:00
"KeyId": "change_to_your_keyid",
"SecretKey": "change_to_your_secretkey"
}
}
2022-02-18 01:22:31 +08:00
```
2017-05-02 21:08:28 +08:00
2022-05-09 02:23:45 +08:00
Ignore the `r53_accountname` section. It is a placeholder and will be ignored. You
2017-05-02 21:08:28 +08:00
can use it later when you define your first set of API credentials.
Note that `creds.json` is a JSON file. JSON is very strict about commas
and other formatting. There are a few different ways to check for typos:
Python:
2023-01-20 20:56:20 +08:00
```shell
2022-11-01 06:09:43 +08:00
python -m json.tool creds.json
```
2017-05-02 21:08:28 +08:00
jq:
2023-01-20 20:56:20 +08:00
```shell
2022-11-01 06:09:43 +08:00
jq . < creds.json
```
2017-05-02 21:08:28 +08:00
2020-03-23 01:38:37 +08:00
FYI: `creds.json` fields can be read from an environment variable. The field must begin with a `$` followed by the variable name. No other text. For example:
2017-12-05 19:18:21 +08:00
2022-11-01 06:09:43 +08:00
```json
{
"apikey": "$GANDI_V5_APIKEY"
}
```
2017-05-02 21:08:28 +08:00
2022-11-01 06:09:43 +08:00
## 5. Test the sample files
2017-05-02 21:08:28 +08:00
Before you edit the sample files, verify that the system is working.
First run `dnscontrol preview` and make sure that it completes with
no errors. The preview command is the "dry run" mode that shows
what changes need to be made and never makes any actual changes.
It will use APIs if needed to find out what DNS entries currently
exist.
2022-08-21 08:59:02 +08:00
(All output assumes the `--verbose` flag)
2017-05-02 21:08:28 +08:00
It should look something like this:
2023-01-20 20:56:20 +08:00
```shell
2022-02-18 01:22:31 +08:00
dnscontrol preview
2022-11-01 06:09:43 +08:00
```
```text
2017-05-02 21:08:28 +08:00
Initialized 1 registrars and 1 dns service providers.
******************** Domain: example.com
----- Getting nameservers from: bind
----- DNS Provider: bind... 1 correction
#1: GENERATE_ZONEFILE: example.com
(2 records)
----- Registrar: none
Done. 1 corrections.
2022-02-18 01:22:31 +08:00
```
2017-05-02 21:08:28 +08:00
Next run `dnscontrol push` to actually make the changes. In this
case, the change will be to create a zone file where one didn't
previously exist.
2017-01-12 04:02:45 +08:00
2023-01-20 20:56:20 +08:00
```shell
2022-02-18 01:22:31 +08:00
dnscontrol push
2022-11-01 06:09:43 +08:00
```
```text
2017-05-02 21:08:28 +08:00
Initialized 1 registrars and 1 dns service providers.
******************** Domain: example.com
----- Getting nameservers from: bind
----- DNS Provider: bind... 1 correction
#1: GENERATE_ZONEFILE: example.com
(2 records)
2017-01-12 04:02:45 +08:00
2017-05-02 21:08:28 +08:00
CREATING ZONEFILE: zones/example.com.zone
SUCCESS!
----- Registrar: none
Done. 1 corrections.
2022-02-18 01:22:31 +08:00
```
2017-05-02 21:08:28 +08:00
2022-11-01 06:09:43 +08:00
## 6. Make a change
2017-05-02 21:08:28 +08:00
Try making a change to `dnsconfig.js` . For example, change the IP
address of in `A('@', '1.2.3.4')` or add an additional A record.
In our case, we changed the IP address to 10.10.10.10. Previewing
our change looks like this:
2023-01-20 20:56:20 +08:00
```shell
2022-02-18 01:22:31 +08:00
dnscontrol preview
2022-11-01 06:09:43 +08:00
```
```text
2017-05-02 21:08:28 +08:00
Initialized 1 registrars and 1 dns service providers.
******************** Domain: example.com
----- Getting nameservers from: bind
----- DNS Provider: bind... 1 correction
#1: GENERATE_ZONEFILE: example.com
MODIFY A example.com: (1.2.3.4 300) -> (10.10.10.10 300)
----- Registrar: none
Done. 1 corrections.
2022-02-18 01:22:31 +08:00
```
2017-01-12 04:02:45 +08:00
2017-05-02 21:08:28 +08:00
Notice that it read the old zone file and was able to produce a
"diff" between the old `A` record and the new one. If the zonefile
didn't exist, the output would look different because the zone file
was being created from scratch.
2017-01-12 04:02:45 +08:00
2017-05-02 21:08:28 +08:00
Run `dnscontrol push` to see the system generate a new zone file.
2017-04-14 00:46:47 +08:00
2017-05-02 21:08:28 +08:00
Other providers use an API do do updates. In those cases the
individual changes will translate into API calls that update the
specific records.
2017-04-14 00:46:47 +08:00
2017-05-02 21:08:28 +08:00
Take a look at the `zones/example.com.zone` file. It should look
like:
2022-02-18 01:22:31 +08:00
```text
2017-05-02 21:08:28 +08:00
$TTL 300
@ IN SOA DEFAULT_NOT_SET. DEFAULT_NOT_SET. 1 3600 600 604800 1440
IN A 10.10.10.10
2022-02-18 01:22:31 +08:00
```
2017-05-02 21:08:28 +08:00
You can change the "DEFAULT_NOT_SET" text by following the documentation
2023-01-20 20:56:20 +08:00
for the [BIND provider ](providers/bind.md ) to set
2017-05-02 21:08:28 +08:00
the "master" and "mbox" settings. Try that now.
## 7. Use your own domains
Now that we know the system is working for test data, try controlling
a real domain (or a test domain if you have one).
Set up the provider: Add the providers's definition to `dnsconfig.js`
and list any credentials in `creds.json` . Each provider is different.
2023-01-20 20:56:20 +08:00
See [the provider docs ](providers.md ) for
2017-05-02 21:08:28 +08:00
specifics.
Edit the domain: Add the `D()` entry for the domain, or repurpose
the `example.com` domain. Add individual `A()` , `MX()` and other
records as needed. Remember that the first parameter to `D()` is
always a Registrar.
Run `dnscontrol preview` to test your work. It may take a few tries
to list all the DNS records that make up the domain. When preview
shows no changes required, then you know you are at feature parity.
2023-01-20 20:56:20 +08:00
The [Migrating ](migrating.md ) doc has advice
2017-05-02 21:08:28 +08:00
about converting from other systems.
You can manually create the `D()` statements, or you can
2017-04-14 00:46:47 +08:00
generate them automatically using the
2023-01-20 20:56:20 +08:00
[dnscontrol get-zones ](get-zones.md )
2020-02-18 21:59:18 +08:00
command to import the zone from (most) providers and output it as code
that can be added to `dnsconfig.js` and used with very little
modification.
2017-05-02 21:08:28 +08:00
Now you can make change to the domain(s) and run `dnscontrol preview`
## 8. Production Advice
If you are going to use this in production, we highly recommend the following:
* Store the configuration files in Git.
2020-11-19 05:15:18 +08:00
* Encrypt the `creds.json` file before storing it in Git. Do NOT store
API keys or other credentials without encrypting them.
2023-01-20 20:56:20 +08:00
* Use a CI/CD tool like [Gitlab ](ci-cd-gitlab.md ), Jenkins, CircleCI, [GitHub Actions ](https://github.com/StackExchange/dnscontrol#via-github-actions-gha ), etc. to automatically push DNS changes.
2022-11-01 06:09:43 +08:00
* Join the DNSControl community. File [issues ](https://github.com/StackExchange/dnscontrol/issues ) and [PRs ](https://github.com/StackExchange/dnscontrol/pulls ).