Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

DNSSEC: signing a DNS zone

After this lesson: I can sign a DNS zone and show that a changed record no longer verifies.

75 min lesson12 commandsDHCP and DNS lab: configure dnsmasq for a small network in your browser

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Can you trust a DNS answer?

DNS Security Extensions (DNSSEC) add digital signatures to DNS records, so a resolver can check that an answer really came from the zone's owner.

It matters because plain DNS answers carry no proof. A forged answer can send a whole college to the wrong mail server or the wrong sign-in page.

By the end of this lesson

Note

I can sign a DNS zone and show that a changed record no longer verifies.

Key words

WordWhat it meansExample
Zonethe set of DNS records one owner looks afterexample.test
DNSKEYa record holding a zone's public key
RRSIGa record holding the signature of a set of records
DS recorda hash of a child zone's key, kept by its parent
Chain of trusteach parent vouching for its child's key, down from the root

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Each zone signs, and its parent vouches

A signed zone publishes its public key in a DNSKEY record and signs every set of records with an RRSIG. A resolver checks each RRSIG with the DNSKEY.

But why trust the DNSKEY? Because the parent zone holds a DS record, a hash of it, signed by the parent. Each parent vouches for its child, up to the root.

Worked example: the records DNSSEC adds

RecordWhereWhat it does
DNSKEY 257example.testThe key-signing key: signs the zone's keys
DNSKEY 256example.testThe zone-signing key: signs every other record
RRSIGBeside each setThe signature, with dates and the key tag
NSECBetween namesProves a name does not exist
DSIn the parent, test.A hash of the key-signing key

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Install the signing tools

Command
sudo apt-get install -y -qq bind9-utils

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the zone for example.test

Command
mkdir -p mail && printf '%s\n' 'example.test. 3600 IN SOA ns1.example.test. hostmaster.example.test. 1 7200 900 1209600 300' 'example.test. 3600 IN NS ns1.example.test.' 'example.test. 3600 IN MX 10 mail.example.test.' 'example.test. 3600 IN TXT "v=spf1 mx -all"' 'ns1.example.test. 3600 IN A 10.0.10.1' 'mail.example.test. 3600 IN A 10.0.10.25' > mail/example.test.zone

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check the zone file

Command
named-checkzone example.test mail/example.test.zone

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Make the key-signing key

Command
dnssec-keygen -K mail -a ECDSAP256SHA256 -f KSK example.test

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Make the zone-signing key

Command
dnssec-keygen -K mail -a ECDSAP256SHA256 example.test

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Sign the zone

Command
dnssec-signzone -K mail -S -O full -o example.test -f mail/signed.zone mail/example.test.zone

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Look at the mail server's records

Command
grep '^mail' mail/signed.zone | cut -c1-90

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check the Run

Have a go

Check the Run

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Verify the signed zone

Command
dnssec-verify -o example.test mail/signed.zone

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Change one address in the signed file

Command
sed -i 's/10.0.10.25/10.0.10.99/' mail/signed.zone

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Verify the changed zone

Command
dnssec-verify -o example.test mail/signed.zone

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What the two checks printed

RunPrintedMeaning
Before the changeZone fully signed: Algorithm: ECDSAP256SHA256: KSKs: 1 active ... ZSKs: 1 activeEvery signature checks
After the changeNo correct ECDSAP256SHA256 signature for mail.example.test AThe address no longer matches its RRSIG
After the changeDNSSEC completeness test failed.A validating resolver would refuse the answer

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think DNSSEC encrypts DNS. It signs answers and hides nothing: anyone can still read the question and the answer. Encryption is a different tool, DNS over TLS or HTTPS.

The parent needs the DS record

Signing is not enough on its own. Until the parent zone publishes a DS record for the key-signing key, resolvers have no reason to trust the DNSKEY.

The owner gives the DS record to the registrar. When keys change, the old DS must stay until the new one is everywhere, or the zone stops resolving for validating resolvers.

Make the DS record for the parent

Command
dnssec-dsfromkey -2 -f mail/signed.zone example.test

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Show the key-signing key

Command
grep 'DNSKEY.*257' mail/signed.zone

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Try it: a hash changes completely

Code: python
# A DS record is a hash of the child's signing key, kept by the parent.
import hashlib

key_a = b"pretend key of example.test"
key_b = b"pretend key of example.test!"
print(hashlib.sha256(key_a).hexdigest()[:16])
print(hashlib.sha256(key_b).hexdigest()[:16])
# One character more gives a completely different hash.
# Change key_b back to match key_a, then press Run.

Make a free account to save your work and track your progress.

Assignment: key tag and DS digest

Work out what dnssec-dsfromkey prints, from a DNSKEY record. A DNSKEY's data is its flags (2 bytes), protocol (1 byte), algorithm (1 byte) and the key decoded from base64; the base64 may contain spaces.

key_tag(flags, protocol, algorithm, key) adds the data's bytes, the even-numbered ones (0, 2, 4 ...) times 256 and the odd ones as they are, then adds the total divided by 65536 (whole number) to itself and keeps the remainder after dividing by 65536.

ds_digest(owner, flags, protocol, algorithm, key) returns the SHA-256, in capital hex, of the owner name in wire form followed by the data. Wire form is each label in lower case after a byte holding its length, then a zero byte; a final dot is ignored.

Code: python
import base64
import hashlib


def key_tag(flags, protocol, algorithm, key):
    return 0


def ds_digest(owner, flags, protocol, algorithm, key):
    return ""

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.