
Most “mystery” deliverability problems after routine maintenance aren’t SPF-related. They’re rarely caused by a new IP.
They usually trace back to DKIM. A key changed before DNS updated everywhere. Or a selector got reused and someone cached the old record.
This DKIM key rotation tutorial walks you through rotating DKIM on a VPS or dedicated server without breaking outbound mail. You’ll use a parallel selector, short TTLs, and a header-based verification checklist.
You can use the same approach on cPanel/WHM, DirectAdmin-style multi-tenant mail servers, or a custom Postfix + OpenDKIM stack. The sequence matters.
Generate a new key. Publish it under a new selector. Switch signing at the right time. Retire the old record after caches and retries have drained.
What you’re rotating (and why selectors matter)
DKIM uses a selector plus your domain to locate a public key in DNS. Your server signs mail with the private key. Receivers verify it using the TXT record at selector._domainkey.example.com.
- Selector: a label like
default,s1,2026q3. - Private key: stored on your server (OpenDKIM, Exim, etc.).
- Public key: published in DNS as a TXT record.
The safest pattern is new selector, new key. Swapping the key under an existing selector is where rotations go sideways.
DNS caches, slow secondaries, and delayed verification (for retries) can leave you with a long tail of DKIM failures.
Prerequisites and a quick “don’t break mail” checklist
Before touching DKIM, confirm what actually sends mail for the domain. On hosting setups, outbound mail often comes from multiple places.
Common sources include PHP forms, mailbox users, a transactional provider, and maybe a CRM.
- List all outbound sources (server mail, SMTP relay, external provider).
- Confirm you control the DNS zone (or coordinate with the DNS owner).
- Plan a selector naming scheme you won’t reuse.
- Lower DKIM TXT TTL ahead of time (e.g., 300 seconds).
If you’re building your own mail-sending stack on a VPS, get the basics right first. Focus on clean rDNS and aligned authentication.
These two guides pair well with a rotation: email authentication setup guide (SPF/DKIM/DMARC/PTR) and the rDNS setup guide.
Want a server where you can control mail, DNS, and keys end-to-end? A HostMyCode VPS gives you root access for OpenDKIM/Postfix.
If you’d rather have help with mail stack hygiene and safer change windows, managed VPS hosting is the better fit.
DKIM key rotation tutorial: zero-downtime plan (parallel selector)
Use this rollout plan for production changes:
- Pick a new selector (example:
2026q3). - Generate a new key pair on the server.
- Publish the new public key to DNS under the new selector.
- Wait for propagation (based on TTL + your DNS provider behavior).
- Switch signing to the new selector (or sign multiple domains/streams).
- Verify with real headers, not guesses.
- Keep the old selector record for a safety window, then remove it.
This works because you never create a “no matching DNS” gap. Mail signed before the switch still validates because the old DKIM record remains published.
Mail signed after the switch validates because the new record is already visible.
Step 1: Lower TTL (DNS) before you change anything
Do this a few hours before rotation. If your current DKIM TXT TTL is 3600 or 14400, drop it to 300.
Also remember: changing TTL doesn’t instantly rewire every resolver. You still have to wait for caches to expire.
Example DKIM records to locate:
default._domainkey.example.comTXTs1._domainkey.example.comTXT
If you run your own nameservers (common on WHM), delegation or glue mistakes can make propagation look “random.” That can make a DKIM cutover feel inconsistent.
If that’s your setup, keep this open: cPanel nameserver setup guide (glue records & delegation).
Step 2: Rotate DKIM on cPanel/WHM (recommended method)
On cPanel servers, Exim typically handles DKIM signing, with keys stored per domain. Exact locations vary by distro and cPanel build.
You’ll commonly see:
- Keys:
/var/cpanel/domain_keys/private/and/var/cpanel/domain_keys/public/ - DKIM status: WHM → Email → Email Authentication
Important constraint: Many cPanel setups stick to the default selector. For a low-risk rotation, you still want a new selector.
If your environment can’t manage multiple selectors cleanly in the UI, you can still rotate safely. Stage the DNS change first. Then avoid any moment where Exim signs with a selector that doesn’t exist in DNS.
2A) Identify the current selector and record
Start by checking the current DKIM TXT record in DNS and writing down the selector. Then confirm what the server is actually using to sign.
This is often shown in WHM’s Email Authentication page.
From your workstation or the server, query DNS:
dig +short TXT default._domainkey.example.com
2B) Generate a new key and selector (server-side)
If you manage DKIM with OpenDKIM separately, skip to the Postfix/OpenDKIM section below. For cPanel-managed keys, the safest workflow is straightforward:
- Create a new selector (example:
2026q3). - Generate a 2048-bit key pair.
Selector control isn’t exposed consistently across cPanel versions and plugins. If your system stores keys as files, generate the new pair in a temporary directory first:
sudo mkdir -p /root/dkim-rotate/example.com/2026q3
cd /root/dkim-rotate/example.com/2026q3
sudo openssl genrsa -out 2026q3.private 2048
sudo openssl rsa -in 2026q3.private -pubout -out 2026q3.public
Then format the public key into a DNS-friendly TXT value. DKIM TXT records usually follow this shape:
2026q3._domainkey.example.com. 300 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."
You can extract the base64 body (remove header/footer and newlines):
awk 'NF {sub(/\r/, ""); printf "%s",$0;}' 2026q3.public \
| sed 's/-----BEGIN PUBLIC KEY-----//; s/-----END PUBLIC KEY-----//'
echo
2C) Publish the new selector in DNS (parallel to the old)
Add a new TXT record for 2026q3._domainkey.example.com with TTL 300. Leave the old selector record exactly as-is.
Pitfall: Some DNS panels wrap long TXT strings badly. If your provider supports it, split the value into quoted chunks.
DNS will concatenate them. Example:
"v=DKIM1; k=rsa; p=MIIBIjANBgkqh..." "...rest-of-key..."
2D) Switch signing to the new selector
The cutover method depends on how DKIM signing is implemented on your server:
- If cPanel manages DKIM keys and selector internally, use WHM tools or supported configuration to regenerate/replace keys, then confirm the selector used in headers.
- If you use OpenDKIM alongside cPanel, follow the OpenDKIM section and set Exim/Postfix to pass mail through OpenDKIM.
After switching, send a test email to a mailbox you control (Gmail, Outlook, or a test domain). Inspect the headers for DKIM-Signature.
Confirm the selector shows s=2026q3.
Step 3: Rotate DKIM on Postfix + OpenDKIM (Ubuntu/Debian-friendly)
This flow is consistent and works well on Ubuntu 24.04/26.04-era VPS builds. You’ll generate a new key, add it to OpenDKIM’s tables, publish DNS, then reload services.
3A) Locate your OpenDKIM config files
Common paths:
/etc/opendkim.conf/etc/opendkim/keys//etc/opendkim/KeyTable/etc/opendkim/SigningTable/etc/opendkim/TrustedHosts
Confirm the service is running:
systemctl status opendkim --no-pager
3B) Generate a new selector key
sudo mkdir -p /etc/opendkim/keys/example.com
cd /etc/opendkim/keys/example.com
sudo opendkim-genkey -b 2048 -s 2026q3 -d example.com
sudo chown opendkim:opendkim 2026q3.private
sudo chmod 0600 2026q3.private
This produces:
2026q3.private(private key)2026q3.txt(suggested DNS record)
3C) Update KeyTable and SigningTable (parallel selector)
Add a new line in /etc/opendkim/KeyTable:
2026q3._domainkey.example.com example.com:2026q3:/etc/opendkim/keys/example.com/2026q3.private
Then update /etc/opendkim/SigningTable so new mail uses the new selector. If you currently have:
*@example.com default._domainkey.example.com
Change it to:
*@example.com 2026q3._domainkey.example.com
Keep the old key files and old DNS record live during the change window. You’re only changing which selector signs new mail.
You are not retiring the old selector yet.
3D) Publish the DNS record from 2026q3.txt
Open /etc/opendkim/keys/example.com/2026q3.txt and paste the TXT record into DNS. Then confirm it resolves:
dig +short TXT 2026q3._domainkey.example.com
3E) Reload OpenDKIM and Postfix
sudo systemctl reload opendkim
sudo systemctl reload postfix
Send another test message and verify the selector in the received headers.
Verification: prove it works with real headers (not just DNS lookups)
A TXT record that resolves isn’t proof your mail is validating. You want to see a pass at the receiver.
Check 1: Confirm the DKIM-Signature selector
In the headers of your test email, find:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=2026q3; ...
Check 2: Confirm “DKIM=pass” at the receiver
In Gmail, look in “Authentication-Results”. You want something like:
Authentication-Results: ... dkim=pass header.i=@example.com header.s=2026q3 ...
Check 3: Confirm alignment with DMARC (if you use it)
DMARC alignment typically expects the From: domain to align with DKIM d= and/or SPF. After rotation, DMARC results should look the same as before.
If you’re not sure your DMARC/SPF/DKIM records are clean, compare before and after using: Email authentication setup guide (2026).
Safe retirement: when to remove the old DKIM record
Keep the old selector published until both of these are true:
- Messages signed with the old selector have finished delivering (including retries).
- DNS caches that might still hold the old record have expired.
For typical hosting outbound mail, keep the old selector for 7–14 days. It’s cheap insurance, especially with large mailbox providers and delayed retries.
After the buffer:
- Remove the old selector TXT record from DNS.
- Remove the old private key file from the server (or move it to a secure archive if policy requires).
- Document the rotation date, selector, and key size.
Troubleshooting: common rotation failures and fast fixes
- DKIM=fail right after the switch: the new selector still isn’t visible everywhere. Wait out the TTL, query authoritative DNS, and confirm you published the correct TXT value.
- “No key for signature” in logs: the MTA is signing with a selector missing from OpenDKIM KeyTable, or permissions block reads. Check
/var/log/mail.log, ownershipopendkim:opendkim, and mode0600. - Multiple DKIM signatures appear: not always wrong, but it complicates debugging. Make sure you don’t have both Exim/cPanel DKIM and OpenDKIM signing the same message.
- DNS UI broke the TXT string: re-enter using split quoted strings, then confirm with
digand compare to the original.txtoutput.
If you route outbound mail through a relay/smart host, double-check who is expected to sign. Some relays sign for you. Others require your signature to remain intact.
This guide covers the hosting-side relay workflow: cPanel SMTP relay setup tutorial.
Operational checklist: rotate DKIM keys like you mean it
- Choose a selector you’ll never reuse (date-based works well).
- Lower DKIM TTL to 300 ahead of time.
- Publish new selector record before switching signing.
- Verify with headers: selector, DKIM=pass, DMARC result.
- Keep the old selector published for 7–14 days.
- Remove old key material and update internal docs.
If you’re rotating keys as part of deliverability cleanup or moving domains onto infrastructure you control, HostMyCode fits that workflow well. Start with a HostMyCode VPS for full control of your mail stack, or choose managed VPS hosting if you want help planning the cutover and validating DNS and headers before and after the switch.
FAQ: DKIM key rotation
How often should I rotate DKIM keys in 2026?
For most hosting senders, every 6–12 months is a sensible cadence. Rotate sooner if you suspect key exposure, staff changes, or a compromised server.
Can I rotate DKIM without changing the selector?
You can, but it’s riskier. Changing the key under the same selector creates a period where some receivers verify against the old cached key. A new selector avoids that.
Should I use 1024-bit or 2048-bit DKIM keys?
Use 2048-bit keys unless you have a specific compatibility constraint. Most modern receivers expect 2048-bit for better security margins.
Do I need to rotate DKIM if I move to a new VPS IP?
Not strictly. IP changes affect SPF and reputation more than DKIM. Still, migrations are a good moment to rotate keys since you’re already in a controlled change window.
If you’re changing server IPs on WHM, plan it carefully with this guide: cPanel IP change configuration tutorial.
What’s the fastest way to validate DKIM after rotation?
Send a real message to a major provider and read Authentication-Results in the received headers. DNS lookups alone won’t catch signing misconfigurations.
Summary: rotate with parallel selectors, not hope
DKIM rotation stays boring if you treat it like a controlled rollout. Publish first. Switch second. Verify using received headers.
Then retire the old record after caches and retries are done. If you want a clean platform for email and DNS changes without fighting locked-down environments, run it on a HostMyCode VPS where you control keys, logs, and the full mail path.