Sub topic 13
Protecting the Domain and Authenticating Email
This chapter assumes you know the core record types (A, MX, TXT, NS), how delegation works between a registrar and a registry, and how TTL and caching affect changes. It covers two related jobs. The first is keeping control of the domain itself. The second is proving that mail claiming to come from your domain really did.
Why the domain is a high-value target
Whoever controls your domain's registration or its DNS zone controls your website, your email, and every certificate request that relies on domain validation. An attacker who changes your NS records, or who edits records at your DNS host, can send visitors to a fake site and read mail addressed to you. They can also pass a certificate authority's checks and obtain a valid certificate for your name.
The usual routes to losing a domain are:
- A stolen or guessed registrar account password.
- A social-engineering request that tricks support staff into a transfer or contact change.
- An unauthorized transfer to another registrar.
- A lapsed registration that someone else re-registers.
- Forged DNS answers that reach a resolver's cache.
- A dangling record that points at a service you no longer control.
The protections below map to these routes.
Protecting the registration
Account security
Start at the registrar account, since every other control can be undone from there.
- Use a long, unique password kept in a password manager.
- Turn on multi-factor authentication. Prefer an authenticator app or a hardware security key over SMS, because phone numbers can be hijacked.
- Use a shared role mailbox or a well-protected address as the account contact. The email address on the account is the recovery path, so the domain used for that address should not be the domain it protects.
- Keep contact details current. Transfer approvals and expiry warnings go to these addresses.
Registrar lock and registry lock
A registrar lock (shown in WHOIS or RDAP as clientTransferProhibited) tells the registry to refuse transfers of the domain to another registrar. It is usually a toggle in the registrar's control panel and is on by default at many registrars. To transfer the domain legitimately, you unlock it, obtain an authorization code (also called an EPP code), and give it to the new registrar.
A registry lock (serverTransferProhibited, along with update and delete prohibitions) is a stronger control applied at the registry. Changes require out-of-band verification with the registry operator, so a compromised registrar account is not enough to change the delegation. It usually costs extra and suits high-value domains.
You can check which status flags are set:
whois example.com | grep -i "status"Typical output includes clientTransferProhibited, and may include clientDeleteProhibited and clientUpdateProhibited. RDAP clients show the same flags.
Renewal
An expired domain stops resolving, and after a grace period it can be registered by anyone. Enable auto-renew, keep a valid payment method on file, and consider registering for several years. Renewal notices that land in an inbox hosted on the expiring domain will never arrive once it lapses.
DNSSEC: signing the answers
Ordinary DNS answers are not authenticated. A resolver that receives a forged answer, for example through cache poisoning, has no way to tell. DNSSEC (DNS Security Extensions) adds digital signatures so a validating resolver can check that an answer came from the zone's owner and was not altered.
DNSSEC does not encrypt queries and does not hide anything. It provides authenticity and integrity only.
How the chain of trust works
A signed zone publishes extra records:
| Record | Purpose |
|---|---|
| DNSKEY | The zone's public keys, used to verify signatures. |
| RRSIG | A signature over one set of records (an RRset), such as all A records for a name. |
| DS | A hash of the child zone's key, published in the parent zone. It links the child to the parent. |
| NSEC / NSEC3 | Signed proof that a name does not exist. |
Trust starts at the root zone, whose key is built into validating resolvers as a trust anchor. The root signs the DS record for each TLD. The TLD signs the DS record for your domain. Your zone's key then signs your own records.
Enabling it
Enabling DNSSEC has two steps, and both are required:
- Your DNS host signs the zone and gives you DS record data (key tag, algorithm, digest type, digest).
- You add that DS record at the registrar, which passes it to the registry to publish in the TLD zone.
If you add a DS record that does not match the zone's keys, or if you move the zone to a provider that does not sign it while the old DS remains, validating resolvers return SERVFAIL for your whole domain. Sites then appear to be down for users behind validating resolvers, while non-validating resolvers still work. This is the most common DNSSEC failure.
When moving DNS providers, remove the DS record first (and wait for its TTL to pass), move the zone, then re-enable signing and publish the new DS.
You can inspect DNSSEC data with dig:
dig example.com DNSKEY +short
dig example.com DS +short
dig example.com A +dnssecIn the third command, a validating resolver sets the ad (authenticated data) flag in the response header when validation succeeded. To see the failure case, query with checking disabled and compare:
dig example.com A +cdIf +cd returns an answer while a normal query returns SERVFAIL, validation is the problem.
Email authentication: SPF, DKIM, DMARC
The SMTP protocol does not verify the sender address shown to users. Anyone can send a message that claims to be from [email protected]. Three DNS-based mechanisms let receiving servers check such claims. All three are published as TXT records.
SPF
SPF (Sender Policy Framework) lists which servers may send mail for the domain. A receiving server compares the connecting IP address with the policy in the TXT record at the domain named in the SMTP envelope sender (the MAIL FROM address).
The zone from earlier chapters had this record:
@ IN TXT "v=spf1 mx -all"Read it left to right:
v=spf1marks the record as SPF.mxallows the hosts named in the domain's MX records.-allsays that anything not matched should fail.
Common mechanisms are ip4:, ip6:, a, mx, and include: (which pulls in another domain's policy, such as a mail provider's). The ending matters:
| Ending | Meaning |
|---|---|
| `-all` | Hard fail. Reject or mark unlisted senders. |
| `~all` | Soft fail. Accept but treat as suspicious. |
| `?all` | Neutral. No statement. |
| `+all` | Allow everything. Never use this. |
Gotchas:
- A domain must have only one SPF record. Two
v=spf1TXT records cause a permanent error, and checks fail. - SPF allows at most 10 DNS lookups during evaluation. Each
include,a,mx, andredirectcounts, and nested ones count too. Going over the limit causes a permanent error. - SPF checks the envelope sender, not the visible
From:header. It also breaks when mail is forwarded, because the forwarder's IP is not in your policy.
DKIM
DKIM (DomainKeys Identified Mail) signs each outgoing message. The sending server adds a DKIM-Signature header that covers selected headers and the body. The receiver reads the d= (signing domain) and s= (selector) tags, then fetches the public key from DNS and verifies the signature.
The key lives at selector._domainkey.domain. For selector mail1:
mail1._domainkey IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...IDAQAB"The value after p= is the public key, shortened here. The private key stays on the sending system. Selectors let you publish several keys at once, so you can rotate keys without a gap, and give each sending service its own key. Many providers ask you to add a CNAME instead of a TXT record, which points the selector at a key they host and rotate for you.
Check a published key with:
dig mail1._domainkey.example.com TXT +shortDKIM survives forwarding because the signature travels with the message, but it breaks if a mailing list or gateway alters the signed content.
DMARC
SPF and DKIM each pass or fail without regard to the address people see. DMARC (Domain-based Message Authentication, Reporting and Conformance) ties them to the visible From: domain and tells receivers what to do on failure.
A message passes DMARC if either SPF or DKIM passes and the passing domain aligns with the From: domain. Alignment means the domains match exactly (strict) or share the same organizational domain (relaxed, the default).
The policy is a TXT record at _dmarc.domain:
_dmarc IN TXT "v=DMARC1; p=none; rua=mailto:[email protected]; adkim=r; aspf=r"| Tag | Meaning |
|---|---|
| `p` | Policy for failures: `none`, `quarantine`, or `reject`. |
| `rua` | Address that receives daily aggregate reports. |
| `adkim`, `aspf` | Alignment mode: `r` relaxed or `s` strict. |
| `pct` | Percentage of failing mail the policy applies to. |
| `sp` | Policy for subdomains. |
Roll out in stages. Start with p=none to collect reports without affecting delivery. Use the reports to find every legitimate sender (the marketing platform, the billing system, the helpdesk) and make each one pass SPF or DKIM with alignment. Then move to p=quarantine, optionally with pct=25 rising over time, and finally p=reject. Jumping straight to reject blocks your own legitimate mail from services you forgot.
Checking all three
dig example.com TXT +short
dig _dmarc.example.com TXT +short
dig mail1._domainkey.example.com TXT +shortSend a test message to a mailbox you control and read the Authentication-Results header. It shows spf=pass, dkim=pass, and dmarc=pass when everything is correct.
Related protections
- Dangling records. A CNAME that points to a deleted cloud resource can let someone else claim that target and serve content on your subdomain (subdomain takeover). Remove DNS records when you decommission a service, and audit them regularly.
- CAA records. A CAA record lists which certificate authorities may issue certificates for the domain, for example
example.com. IN CAA 0 issue "letsencrypt.org". Conforming CAs must check it before issuing. - Null SPF for non-sending domains. A domain that never sends mail can publish
v=spf1 -alland a DMARCp=rejectpolicy, and an empty MX (0 .) to say it receives none. - Least-privilege DNS access. Give team members and automation scoped API tokens rather than the account password, and keep zone-change audit logs if your provider offers them.
Summary of controls
| Threat | Control |
|---|---|
| Account takeover | Strong password, MFA, protected recovery email |
| Unauthorized transfer | Registrar lock, registry lock |
| Accidental expiry | Auto-renew, multi-year registration |
| Forged DNS answers | DNSSEC |
| Spoofed sender address | SPF, DKIM, DMARC |
| Rogue certificates | CAA records |
| Subdomain takeover | Remove stale records |
Exercise
Your domain's DMARC record is v=DMARC1; p=reject, and the company newsletter, sent by a third-party service, starts bouncing. SPF for your domain passes only for your own mail servers, and the service signs mail with its own domain d=newsletter-vendor.example. What is wrong, and how do you fix it without weakening the policy for everything else?
Show answer
DMARC needs a passing SPF or DKIM result that aligns with the visible From domain. The vendor's SPF passes for its own envelope domain, and its DKIM signature uses the vendor's domain, so neither aligns with your domain and DMARC fails. Fix it by setting up the vendor's custom domain authentication: publish the DKIM selector record (a TXT or CNAME at selector._domainkey.example.com) so the vendor signs with d=example.com. Optionally add the vendor to SPF with include: if you also want SPF to pass, watching the 10-lookup limit. Lower the policy to p=none or quarantine while testing if needed, but the lasting fix is aligned DKIM.
Exercise
You move your DNS zone to a new provider that does not support DNSSEC, and some users immediately report that the site cannot be reached, though others see it fine. Using dig, how would you confirm the cause, and what should you have done first?
Show answer
The old DS record is still published in the TLD zone, but the new zone has no matching keys, so validating resolvers return SERVFAIL while non-validating ones work. Confirm with dig example.com A (SERVFAIL) versus dig example.com A +cd (returns an answer), and dig example.com DS +short showing a DS record. Fix it by removing the DS record at the registrar. Before moving, you should have removed the DS record and waited for its TTL to expire, then migrated the zone.
Exercise
Why does an SPF record with include: entries sometimes fail with a permanent error even though each include is valid?
Show answer
SPF evaluation is limited to 10 DNS-querying terms (include, a, mx, ptr, exists, redirect), counting nested lookups inside included records. Exceeding that limit produces a permerror. Reduce includes, remove unused services, or replace includes with direct ip4/ip6 entries.