A Postfix mail server can use DANE to keep mail between servers encrypted and make sure it reaches the server it was meant for. Your mail server probably already offers STARTTLS, the command that upgrades an SMTP connection to an encrypted one. The weak spot is that a sending server cannot tell whether the certificate it receives is really yours. Someone in the path can also remove the STARTTLS offer, and the mail then travels in plain text. DANE (DNS-based Authentication of Named Entities) solves this by putting the answer in DNS. You publish a TLSA record, a small DNS entry that names the exact public key your mail server presents. DNSSEC, which signs DNS answers so they cannot be forged, lets the sender trust that record. When the key does not match or encryption is missing, delivery stops and waits instead of quietly falling back to plain text. You will publish a 3 1 1 TLSA record at _25._tcp.mx.example.com and run a validating resolver on the mail host, a local DNS resolver that checks those signatures and the part many setups miss. Then you will turn on DANE for outbound mail in Postfix and follow a renewal routine that keeps mail flowing every ninety days.
What you’ll accomplish
- A DNSSEC-signed zone and a validating resolver on the mail host, with the
ADbit proven present rather than assumed. - A
3 1 1TLSA record derived from the SubjectPublicKeyInfo of your MX certificate, published at_25._tcp.mx.example.com. smtp_tls_security_level = danewithsmtp_dns_support_level = dnssec, so outbound mail authenticates remote MX hosts that publish TLSA records.smtpd_tls_security_level = mayon the receiving side, serving the certificate your record commits to.- A rollover procedure — publish the new record, wait past the TTL, then swap the certificate — and a check that says whether DANE actually engaged.
Prerequisites
- Postfix 3.x from your distribution’s packages, built with DNSSEC support — Debian, Ubuntu and RHEL-family packages are. If yours is not, the
danelevel silently behaves likemayand nothing here will bite. - The zone holding your MX records must be DNSSEC-signed, with the chain complete to the root. A signed zone with no DS record at the parent is unsigned as far as every validator is concerned. If you sign in-house, signing a zone with BIND 9 and rolling keys covers that side.
- A DNSSEC-validating resolver reachable over a trusted path — in practice, on the mail host itself at
127.0.0.1. This is the step almost everyone skips. Postfix trusts theADbit in the reply; if the resolver does not validate, that bit never appears and DANE never applies to a single delivery. - Root or
sudoon the mail host, and the ability to publish records in the MX hostname’s zone. - A TLS certificate and key already in place for the MX hostname, and control over when they are replaced. ACME automation that renews behind your back is a problem here, addressed in step 7.
- MTA-STS and TLS-RPT is the companion piece, not an alternative: DANE anchors trust in a signed DNS chain, MTA-STS in an HTTPS-fetched policy plus the public CA system. Google and Microsoft honour MTA-STS; much of the European hosting world honours DANE. Publishing both is normal.
How it works
A TLSA record answers one question for a sending MTA: which key should the server at this name present? It lives under a prefixed name — _25._tcp. in front of the MX hostname — and carries three numbers plus a hash.
The numbers are usage, selector and matching type. For SMTP, 3 1 1 is the pick that works: usage 3 is DANE-EE, meaning “this is the end-entity certificate, trust it directly, do not consult the public CA system”; selector 1 means the hash covers the SubjectPublicKeyInfo rather than the whole certificate; matching type 1 is SHA-256. The alternative is 2 1 1, DANE-TA, which pins a CA instead of the leaf. 3 1 1 wins for mail because no PKIX path validation happens — a private or self-signed certificate is fine — and because a renewal reusing the same key needs no DNS change, whereas 2 1 1 breaks the moment your CA rotates an intermediate, which public CAs do without telling you.
The chain of signed answers matters more than the record. The MX lookup, the address lookup for the MX hostname, and the TLSA lookup must all validate. If any link is unsigned, Postfix treats the destination as one that does not do DANE and delivers with ordinary opportunistic TLS — no error, no warning, just a different log line. That silence is the whole reason step 2 exists.
On the sending side, smtp_tls_security_level = dane is opportunistic about DANE and mandatory about verification: when usable TLSA records exist over a validated path, TLS becomes required and the certificate must match; when they do not, delivery falls back to may. dane-only removes the fallback and defers instead, which is right for a specific transport to a known partner and wrong as a global default.
Step-by-step
Throughout, example.com is your domain and mx.example.com is the MX hostname.
-
Confirm the zone is signed all the way to the root. Ask a validating public resolver, not your own — you want the chain checked by something that does not share your assumptions.
dig +dnssec MX example.com @9.9.9.9 | grep -E '^;; flags|RRSIG'Expected: the flags line contains
ad, and at least oneRRSIG MXappears in the answer. Ifadis absent, the zone is unsigned or the DS record is missing at the parent — stop here, because everything below depends on it. -
Put a validating resolver on the mail host.
systemd-resolvedat127.0.0.53has a long history of not surfacing theADbit to applications, and a forwarder at your ISP is not a trusted path. Installunboundlocally.sudo apt install -y unbound sudo systemctl enable --now unboundDebian’s package validates by default, with the root trust anchor managed by
unbound-anchor. Add a drop-in to be explicit:# /etc/unbound/unbound.conf.d/dane.conf server: interface: 127.0.0.1 access-control: 127.0.0.0/8 allow harden-dnssec-stripped: yes val-permissive-mode: noPoint
/etc/resolv.confatnameserver 127.0.0.1, then prove it validates by asking for a domain with a deliberately broken chain:dig @127.0.0.1 dnssec-failed.org A | grep 'status:'Expected:
status: SERVFAIL.status: NOERRORwith an address back means the resolver is not validating, and DANE will never engage. -
Compute the SPKI hash. This is the number that goes in the record, and it is derived from the public key, not the certificate file as a whole.
openssl x509 -in /etc/postfix/tls/mx.example.com.crt -noout -pubkey \ | openssl pkey -pubin -outform DER \ | sha256sum | awk '{print $1}'Expected: exactly 64 hexadecimal characters, for example
8cb0fc6c527506a053f4f14c8464bebbd6dede2738d1157b7c4a5c1a3f0e8e0d. Anything longer or shorter means you hashed the wrong thing.You can also compute it straight from the private key — which is what makes pre-publishing possible during a rollover:
openssl pkey -in /etc/postfix/tls/mx.example.com.key -pubout -outform DER \ | sha256sum | awk '{print $1}'Expected: the identical 64 characters. If they disagree, the certificate on disk was not issued for that key.
-
Publish the TLSA record. The owner name is the port and protocol prefixed to the MX hostname — not the mail domain.
_25._tcp.mx.example.com. 3600 IN TLSA 3 1 1 8cb0fc6c527506a053f4f14c8464bebbd6dede2738d1157b7c4a5c1a3f0e8e0dKeep the TTL modest: 3600 is reasonable, lower is better in the week around a renewal, because the TTL is exactly how long you wait during a rollover. Re-sign and reload the zone, then check from outside:
dig +dnssec TLSA _25._tcp.mx.example.com @9.9.9.9 | grep -E '^;; flags|TLSA'Expected:
adin the flags line, oneTLSA 3 1 1 ...record, and anRRSIG TLSAbeside it. Several MX hostnames each need their own record; if an MX name is a CNAME, the record belongs on the final target after expansion. -
Make the receiving side serve what you just committed to. DANE says nothing about
smtpdbeyond the certificate it presents — but it does mean that certificate can no longer change without notice.# /etc/postfix/main.cf — receiving side smtpd_tls_cert_file = /etc/postfix/tls/mx.example.com.crt smtpd_tls_key_file = /etc/postfix/tls/mx.example.com.key smtpd_tls_security_level = may smtpd_tls_loglevel = 1mayis correct on a public MX: it offers STARTTLS to everyone and still accepts mail from senders who cannot do TLS.encryptrejects those senders outright — a policy decision about lost mail, not something DANE needs. Reload and confirm:sudo postfix reload && postconf -n | grep '^smtpd_tls'Expected: the four lines above and nothing you did not intend.
-
Turn on outbound DANE verification. This half protects the mail you send to other people’s DANE-enabled servers.
# /etc/postfix/main.cf — sending side smtp_dns_support_level = dnssec smtp_tls_security_level = dane smtp_host_lookup = dns smtp_tls_loglevel = 1smtp_dns_support_level = dnssecis what makes Postfix request and honour validated answers;danewithout it is inert.smtp_host_lookup = dnsis already the default, but if someone setnativeon this box to work around something, DANE stops working — pin it. Reload and read the effective settings back:sudo postfix reload && postconf smtp_tls_security_level smtp_dns_support_levelExpected:
smtp_tls_security_level = dane smtp_dns_support_level = dnssecOne parameter worth knowing:
smtp_tls_dane_insecure_mx_policydecides what happens when the MX lookup itself was insecure but the MX hostname’s own zone is signed. It defaults todane, meaning Postfix still uses TLSA records found under an MX name it could not authenticate. That is convenient and it is also the weak seam: anyone able to forge the unsigned MX answer can point your mail at a host that publishes perfectly valid TLSA records in its own signed zone. Setting it tomayis the conservative reading — an MX you could not authenticate gets opportunistic TLS and nothing stronger. Check what you are actually running withpostconf -d smtp_tls_dane_insecure_mx_policy. -
Write down the renewal rollover before you need it. This is where DANE deployments break: the certificate is replaced, the TLSA record still hashes the old key, and every DANE-validating sender starts deferring your mail while nothing on your side looks wrong.
The order is the whole trick. Generate the next key, hash it with the second command from step 3, and publish that hash as an additional TLSA record while the old one is still live. Both are valid at once — a sender matches if the presented key matches any record in the set. Wait at least twice the TTL, then install the new certificate and reload Postfix. Remove the stale record a day later, once deliveries match the new one.
_25._tcp.mx.example.com. 3600 IN TLSA 3 1 1 8cb0fc6c527506a053f4f14c8464bebbd6dede2738d1157b7c4a5c1a3f0e8e0d _25._tcp.mx.example.com. 3600 IN TLSA 3 1 1 f31d8a4b0c9e77265a1b3d4e8f0a2c65d97b41e8c3a55f2091d6e7b8c4a30f19If your certificate comes from ACME, the simpler answer is to stop rotating the key:
certbot renew --reuse-keykeeps the same private key across renewals, so the3 1 1hash never changes and there is no rollover to get wrong. Rotate the key deliberately, on your own schedule, using the procedure above.
Validate it works
Start with what your MX looks like to a sender, from a host that is not the mail server:
posttls-finger -c -t30 -T180 -l dane mx.example.com
Expected: a summary ending in Verified TLS connection established to mx.example.com[203.0.113.25]:25: TLSv1.3 with cipher .... The word Verified is the one that matters — it is the state Postfix uses when a DANE match authenticated the peer. Trusted means it fell back to CA-based verification; Untrusted means opportunistic TLS with no authentication at all.
Confirm the match independently with OpenSSL, feeding it the record by hand:
openssl s_client -starttls smtp -connect mx.example.com:25 \
-dane_tlsa_domain mx.example.com \
-dane_tlsa_rrdata "3 1 1 8cb0fc6c527506a053f4f14c8464bebbd6dede2738d1157b7c4a5c1a3f0e8e0d" \
< /dev/null 2>&1 | grep -E 'DANE TLSA|Verification'
Expected: DANE TLSA 3 1 1 ...8cb0fc6c... matched EE certificate at depth 0, followed by Verification: OK. If the digest prints but nothing matched, the record and the served certificate disagree.
Then the outbound direction: send a message to a domain you know publishes TLSA records and read the log:
sudo journalctl -u postfix@- --since '5 min ago' | grep -E 'TLS connection established'
Expected: Verified TLS connection established to ... for that destination. Untrusted TLS connection established where you expected protection means DANE did not engage — go back to step 2 and re-check the AD bit, the cause nine times out of ten.
Finally, confirm the resolver hands Postfix validated answers for the names involved:
dig +dnssec TLSA _25._tcp.mx.example.com @127.0.0.1 | grep '^;; flags'
Expected: ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, ... — the ad token present, and an answer count of 2 because the RRSIG travels with the record.
Troubleshooting
Mail to you defers after a certificate renewal. Senders log Server certificate not verified and their queues show dsn=4.7.5, status=deferred. The TLSA record still hashes the previous key. Republish from the certificate actually being served — the second command in step 3, run against the live key file, gives the correct hash. Deferred mail drains on retry once the record is right, but your bounce timeout is the clock.
DANE never engages and no error appears anywhere. Every outbound delivery logs Untrusted TLS connection established, including to destinations you know publish TLSA. The resolver is not validating, or /etc/resolv.conf still points at a stub that strips the AD bit. Run the dnssec-failed.org check from step 2: an address instead of SERVFAIL is your answer. Postfix cannot distinguish “no DANE here” from “my resolver is not telling me about DANE,” so this fails silently by design.
The hash is 64 characters but nothing ever matches. You hashed the certificate instead of the SubjectPublicKeyInfo, which produces a valid-looking digest for a 3 0 1 record while your zone says 3 1 1. The openssl x509 -noout -pubkey step is not optional — it is what selects the key rather than the whole certificate. Re-run both commands from step 3 and confirm they agree.
Only some senders honour your record. The MX hostname sits in a different zone from the mail domain and that zone is unsigned — or the MX name is a CNAME whose target is unsigned. DANE follows the full chain: MX RRset, CNAME expansion, address records and TLSA lookup all have to validate. Check each name individually with dig +dnssec and look for ad on every one.
Postfix accepts smtp_tls_security_level = dane but behaves like may. The build has no DNSSEC support, so the level degrades quietly. Distribution packages of Postfix 3.x are fine; a binary compiled locally against a resolver library without RES_USE_DNSSEC is not. If posttls-finger reports Untrusted while the same record verifies with openssl s_client, the resolver path or the build is where to look.
When this is the wrong approach
If your registrar or DNS host does not support DNSSEC — or supports it but gives you no reliable way to add a second TLSA record during a rollover — DANE is not available to you today, and no amount of Postfix configuration changes that. Publish MTA-STS instead: it needs a web server and a TXT record, and it reaches the large mailbox providers that do not do DANE anyway.
If your certificate is issued by ACME and renewal is fully automated by something you do not control — a load balancer, a platform, a hosting panel — the rollover window is where you will get hurt. Either pin the key with --reuse-key and treat key rotation as a scheduled operation, or do not publish TLSA records at all. A DANE deployment that defers mail four times a year is worse than none.
And if your mail is hosted rather than self-run, the TLSA record belongs to whoever controls the certificate. A record for a certificate you do not manage holds until the provider rotates it, then breaks without warning — ask them whether they publish DANE records themselves.
The Postfix documentation is worth reading directly here: the DANE sections of TLS_README and the parameter reference in postconf(5) are precise about what each security level does when a lookup is insecure, which is the detail that decides whether your setup fails open or fails closed.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.