Zones and records¶
This page shows how to add and change the records of a primary zone, accept dynamic updates from a
client such as nsupdate, and let Ninlil write the matching PTR records. A zone is one part
of the DNS name space that Ninlil answers for, stored as a list of records.
Before you start¶
- A running Ninlil and the
example.testzone from the Quick start, with its SOA record and thewwwA record. The commands use the Quick start values: the API onhttps://127.0.0.1:18443and DNS on port15300. Replace them if you chose other ports. - A signed-in API token. Step 4 of the Quick start prints it. A token is valid for 15 minutes by
default
(
NINLIL_JWT_ACCESS_TOKEN_LIFETIME). A request with an expired token answers401with no body: sign in again.<token>stands for theaccessTokenvalue in every command.-kaccepts Ninlil's self-signed certificate. - A user that holds the
zones:readandzones:writepermissions. The bootstrap administrator holds every permission. -
digandnsupdate(your distribution's DNS utilities package provides both). Check them:dig -v nsupdate -V -
Look up the zone's
id. The commands call it<zone-id>:curl -k 'https://127.0.0.1:18443/api/zones?skip=0&take=100' -H 'Authorization: Bearer <token>'{"items":[{"id":"<zone-id>","name":"example.test","type":"Primary", ...A page holds 50 zones unless you set
take(500 at most). Raiseskipto reach the next page.
The examples call the API on 127.0.0.1 with curl -k, which skips the certificate check.
That is safe only on the machine that runs Ninlil; see Self-signed certificate.
Steps¶
Add and change records¶
-
Add an MX record and a CNAME record. A record's
nameis its full owner name. The name@stands for the zone's own name. Each record'sdataobject has the fields of its type (preferenceandexchangefor MX,targetfor CNAME,valuesfor TXT). The console form shows the fields of the type you pick, and/swaggeron your Ninlil lists them for every type.curl -k https://127.0.0.1:18443/api/zones/<zone-id>/records -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"example.test","type":"MX","timeToLiveSeconds":300,"data":{"preference":10,"exchange":"mail.example.test"}}' curl -k https://127.0.0.1:18443/api/zones/<zone-id>/records -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"web.example.test","type":"CNAME","timeToLiveSeconds":300,"data":{"target":"www.example.test"}}'{"id":"<mx-record-id>","zoneId":"<zone-id>","name":"example.test","type":"MX","class":"IN", ... {"id":"...","zoneId":"<zone-id>","name":"web.example.test","type":"CNAME","class":"IN", ...Copy the MX record's
idas<mx-record-id>. In the console: open Zones, press Manage records on the zone's row, press Add record, fill in the form and press Save. 2. To find theidof a record you did not just add, list the zone's records:curl -k 'https://127.0.0.1:18443/api/zones/<zone-id>/records?skip=0&take=100' -H 'Authorization: Bearer <token>' -
Change the MX preference. A
PATCHchanges only the fields you send, but it replacesdataas a whole, so send every field of the type:curl -k -X PATCH https://127.0.0.1:18443/api/zones/<zone-id>/records/<mx-record-id> -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"data":{"preference":20,"exchange":"mail.example.test"}}'The answer is
204with no body. 4. To take a record out of service without deleting it, send{"isDisabled":true}in the same kind ofPATCH. To delete it, sendDELETEto the same address.
Accept dynamic updates (optional)¶
A client can change a zone's records with an RFC 2136 dynamic update. Ninlil accepts an update only
for a Primary or CloudPrimary zone that opts in, and only when the update is signed with a TSIG
key that the zone lists.
-
Create a TSIG key. Leave out
secretand Ninlil generates one. The answer shows the secret once; copy it as<secret>:curl -k https://127.0.0.1:18443/api/tsig-keys -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"update-key"}'{"key":{"id":"...","name":"update-key","algorithmName":"hmac-sha256", ...},"secret":"<secret>"}In the console: TSIG Keys, New key. That page needs the
tsigkeys:writepermission. 2. Turn updates on for the zone and list the key. An empty list accepts no key:curl -k -X PATCH https://127.0.0.1:18443/api/zones/<zone-id> -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"dynamicUpdateEnabled":true,"updateTsigKeyNames":["update-key"]}'In the console: edit the zone, open Dynamic updates & transfers, tick Accept RFC 2136 dynamic updates and tick the key under Keys allowed to send dynamic updates. 3. Write an update file and send it, signed with the key:
printf 'server 127.0.0.1 15300\nzone example.test\nupdate add dyn.example.test. 300 A 192.0.2.99\nsend\n' > update.txt nsupdate -y 'hmac-sha256:update-key:<secret>' update.txtnsupdateprints nothing when the update succeeds.
Keep PTR records in step (optional)¶
Ninlil can write a PTR record for every A and AAAA record of a zone into the matching reverse zone.
-
Create the reverse zone and its SOA record. The reverse zone for
192.0.2.0/24is2.0.192.in-addr.arpa. Copy the first answer'sidas<reverse-zone-id>:curl -k https://127.0.0.1:18443/api/zones -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"2.0.192.in-addr.arpa","type":"Primary"}' curl -k https://127.0.0.1:18443/api/zones/<reverse-zone-id>/records -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"2.0.192.in-addr.arpa","type":"SOA","timeToLiveSeconds":3600,"data":{"primaryNameServer":"ns1.example.test","responsiblePersonMailbox":"admin.example.test","serial":1,"refreshSeconds":3600,"retrySeconds":900,"expireSeconds":1209600,"minimumTtlSeconds":3600}}' -
Turn PTR management on for
example.test. A pass in the background writes the records within a few seconds:curl -k -X PATCH https://127.0.0.1:18443/api/zones/<zone-id> -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"autoManagePtrRecords":true}'The answer is
204.POST /api/zones/<zone-id>/reconcile-ptrruns one pass on demand.
Check that it worked¶
-
Ask for the records you added:
dig @127.0.0.1 -p 15300 example.test MX +noall +answer dig @127.0.0.1 -p 15300 web.example.test A +noall +answerexample.test. 300 IN MX 20 mail.example.test. web.example.test. 300 IN CNAME www.example.test. www.example.test. 3600 IN A 192.0.2.10The CNAME answer also carries the A record it points at. 2. The SOA serial rises by one for every accepted change, so you never edit it. Read it (your values differ):
dig @127.0.0.1 -p 15300 example.test SOA +noall +answerexample.test. 3600 IN SOA ns1.example.test. admin.example.test. 5 3600 900 1209600 3600 -
After the dynamic update:
dig @127.0.0.1 -p 15300 dyn.example.test A +noall +answerdyn.example.test. 300 IN A 192.0.2.99 -
After the PTR pass:
dig @127.0.0.1 -p 15300 -x 192.0.2.10 +noall +answer10.2.0.192.in-addr.arpa. 3600 IN PTR www.example.test.
Good to know¶
- A zone you create has no records. Its first record must be its SOA record. Every accepted change afterwards advances the serial.
- A disabled record is kept but never answered. A disabled zone answers queries with
REFUSEDand updates withNOTAUTH. - A record with
excludeFromSyncset stays on this server: zone transfers and cloud pushes never send it. - Each zone lists its own TSIG keys:
updateTsigKeyNamesfor updates andtransferTsigKeyNamesfor transfers. A key is not valid for a zone that does not list it. - PTR management works for
PrimaryandCloudPrimaryzones.ptrIpv4PrefixLength(default 24) sets the size of each reverse zone. The README lists the other zone types and the full rules: Zones and records. - Settings: the PTR and NOTIFY defaults are in the Authoritative DNS engine table and the TSIG clock tolerance is in the TSIG table.
When something goes wrong¶
401with no body. The token expired. Sign in again.400"A zone's very first record must be its own SOA record." Add the SOA record first. The Quick start shows the command.400"'www' is not in zone 'example.test'; did you mean 'www.example.test'?" A record name must be the zone's name or a name below it. Write the full name, or@for the zone's own name.nsupdateprintsupdate failed: REFUSED. Ninlil verified nothing that lets the update in. Check, in this order: the zone hasdynamicUpdateEnabledset totrue; you passed a key withnsupdate -y; the key's name is in the zone'supdateTsigKeyNames. A key that exists but is not listed for the zone getsREFUSED.nsupdateprintsupdate failed: NOTAUTH(BADSIG). The secret is wrong. Use the secret that the key creation answered.nsupdateprintsupdate failed: NOTAUTH(BADKEY). Ninlil has no key of that name. Check the name you pass tonsupdate -y.nsupdateprintsupdate failed: NOTAUTH. The zone name in the update file is not a zone that Ninlil hosts (a disabled zone counts as not hosted), or the update names a class other thanIN.
Next¶
- DNSSEC: sign the zone.
- Secondary zones and transfers: copy the zone to another server.
- Cloud DNS sync: keep the zone in step with a provider.