Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 36 ยท DNS and Proxying

DNSSEC, SPF, DKIM and DMARC with Cloudflare DNS

Protect your domain with DNSSEC and email authentication: enable DNSSEC in Cloudflare, add the DS record, and write SPF, DKIM and DMARC TXT records correctly.

DNS was designed without proof of authenticity: a resolver simply believes the answer it receives. Two families of records add that proof. DNSSEC signs DNS answers so resolvers can detect forgery. SPF, DKIM and DMARC are TXT records that tell the world which servers may send email for your domain and what to do with impostors. Cloudflare makes both easy to publish.

DNSSEC in one picture

With DNSSEC the zone owner signs every record set with a private key. The matching public key is published in the zone (as a DNSKEY record), and a fingerprint of that key, the DS record, is published in the parent zone (the .com registry). A validating resolver follows the chain from the root downwards and rejects any answer whose signature does not check out.

flowchart TB
  Root["Root zone (trust anchor)"] --> TLD[".com publishes DS for example.com"]
  TLD --> Z["example.com DNSKEY signs records"]
  Z --> R["A, MX, TXT answers carry signatures"]

If any link in the chain is wrong, validating resolvers return an error instead of a forged answer.

DNSSEC does not encrypt anything; it protects integrity, against cache poisoning and spoofed answers.

Enabling it

  1. In the dashboard open DNS > Settings and choose Enable DNSSEC. Cloudflare generates the keys and signs the zone.
  2. Cloudflare shows the DS record values: key tag, algorithm, digest type and digest.
  3. Log in to your registrar and add a DS record with exactly those values. (If Cloudflare is also your registrar, it does this for you.)
  4. Wait for the status to become Active.

Algorithm 13 (ECDSA P-256 with SHA-256) is the usual default: small keys, fast validation. Do not publish the DS before Cloudflare is authoritative for the zone, and remove it before leaving Cloudflare, otherwise validating resolvers treat your domain as broken and visitors get failures.

Email authentication: why three records?

Email's original design lets anyone write any "From" address. Receivers fight forgery with three complementary checks, each a TXT record in your DNS.

Mechanism Question it answers Where the record lives
SPF Is this server allowed to send for the domain? TXT at the domain
DKIM Was the message signed by a key belonging to the domain, and untouched? TXT at selector._domainkey
DMARC What should receivers do if SPF/DKIM fail to align, and who wants reports? TXT at _dmarc

SPF

TEXT
example.com.  TXT  "v=spf1 include:_spf.mailprovider.net ip4:203.0.113.25 -all"

Read left to right: allow the servers listed by the provider, allow this IPv4 address, and -all rejects everything else (~all is a softer "soft fail"). Rules:

  • You may publish only one SPF record per name.
  • Evaluating the record may cause at most 10 DNS lookups (each include, a, mx, redirect and similar counts). Over the limit means a permanent error and mail may be rejected.

DKIM

Your mail provider signs outgoing messages with a private key and gives you a public key to publish:

TEXT
selector1._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."

Some providers instead ask for a CNAME at that name; follow the provider's instructions exactly. Receivers fetch the key by the selector named in the message's DKIM-Signature header.

DMARC

TEXT
_dmarc.example.com.  TXT  "v=DMARC1; p=none; rua=mailto:[email protected]"

p is the policy: none (monitor only), quarantine (send to spam) or reject. Start with none, read the aggregate reports sent to rua, fix legitimate senders, then tighten to quarantine and finally reject. DMARC passes when SPF or DKIM pass and the domain aligns with the visible From address.

Stand-in: SPF lookup counter

The 10-lookup limit surprises many teams that add one email service after another. This stand-in models a zone and counts lookups.

JS Stand-in: count SPF DNS lookups

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Add more include: entries and watch the counter. The usual cures are removing services you no longer use, replacing include of large providers with their IP ranges, or using a mail provider that "flattens" SPF for you.

Stand-in: DMARC record parser

JS Stand-in: parse and explain a DMARC record

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Email Routing and Cloudflare

Cloudflare can also route incoming mail: Email > Email Routing creates addresses like [email protected] that forward to an existing inbox, and it adds the MX and SPF records automatically. It forwards mail; it does not provide mailboxes or sending. Sending still needs a mail provider and the SPF/DKIM/DMARC records above.

Checklist

  1. Enable DNSSEC and add the DS record at the registrar.
  2. One SPF record, under 10 lookups, ending in -all or ~all.
  3. DKIM published for every sending service.
  4. DMARC at p=none with reports, tightened over time.
  5. Mail hostnames are grey-cloud records.
  6. Test with a mail checker and send test messages to different providers.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does DNSSEC protect?

    DNSSEC signs records; it does not encrypt queries.
  2. 2. Where do you put the DS record that Cloudflare gives you?

    The DS record must be published in the parent zone, which is managed through the registrar.
  3. 3. How many SPF records may a name have?

    Multiple SPF records give a permanent error. Merge them into one.
  4. 4. Which DMARC policy only monitors without affecting delivery?

    p=none collects reports first so you can fix legitimate senders.

Summary

  • DNSSEC signs DNS data; enable it in Cloudflare and add the DS record at the registrar; remove it before moving away.
  • SPF lists allowed senders (one record, at most 10 lookups), DKIM signs mail, DMARC sets policy and reporting.
  • Start DMARC at none, read reports, then tighten.
  • Email Routing forwards incoming mail but is not a mailbox provider.

Next: How CDN caching works