Qvantor logo QvantorInfrastructure, explained plainly
Guides

DKIM Key Rotation Without Breaking Your Outgoing Email

Your DKIM key was generated years ago, probably by someone who no longer works with you, and nobody knows if it is 1024 or 2048 bits.

A server rack in a small office with a laptop showing a DNS records table beside two printed key labels

Your DKIM key was generated years ago, probably by someone who no longer works with you, and nobody knows if it is 1024 or 2048 bits. Swapping it feels risky because one wrong DNS record can push every outgoing message into spam folders by lunchtime. A clean DKIM key rotation avoids that by running the old and new keys side by side, so receivers never see a gap.

This guide walks through the exact order I use on small company domains: publish first, sign second, retire last. It works for a self hosted Postfix and OpenDKIM box and for hosted providers that let you bring your own selector.

Why DKIM key rotation matters more than people think

A DKIM private key signs every message you send. If that key leaks from an old backup, a former contractor's laptop or a misconfigured server, anyone holding it can send mail that passes DKIM as your domain. DMARC will then happily mark that mail as aligned.

There is also a plain strength problem. Plenty of domains still publish 1024 bit RSA keys from around 2015. They are not broken in practice, but large receivers have been signalling for years that 2048 bits is the floor they expect. Rotating gives you a natural moment to upgrade.

The practical targets I give clients:

  • Rotate at least once every 12 months, or every 6 months if several people have server access.
  • Rotate immediately when someone with key access leaves, or after any server compromise.
  • Use 2048 bit RSA. Some DNS panels choke on the long TXT value, which we will handle below.

Before you start the rotation

Spend ten minutes on inventory. Rotations fail because of senders you forgot, not because of the cryptography.

  1. List every system that sends mail as your domain: the main mailbox provider, the newsletter tool, the invoicing app, the website contact form, the helpdesk.
  2. For each one, note the selector it signs with. Open a recent message from that system, view the raw headers and find the s= value inside the DKIM-Signature header. That value is the selector.
  3. Check your current record with a DNS lookup on selector._domainkey.yourdomain and copy the TXT value somewhere safe.
  4. Lower the TTL on the existing DKIM record to 300 seconds a day ahead, so any rollback propagates quickly.

Only rotate the selectors you control. Third party senders such as a newsletter platform usually rotate their own keys behind a CNAME, and you should leave those alone.

The DKIM key rotation steps in order

The core rule: never replace the key behind an existing selector. Create a new selector instead. Selector names are free, so use something dated like s202611. That way you can tell at a glance which key is current.

Step 1: generate the new key pair

On an OpenDKIM server the command looks like this: opendkim-genkey -b 2048 -d yourdomain.com -s s202611. It produces two files, the private key and a text file holding the DNS record. Set the private key to be owned by the opendkim user with permissions 600. On a hosted provider, use its admin panel to add a new DKIM key; it will show you the record to publish.

Step 2: publish the new public key

Add a TXT record at s202611._domainkey.yourdomain.com with the value v=DKIM1; k=rsa; p= followed by the long base64 string. A 2048 bit key is about 400 characters, longer than the 255 character limit for a single TXT string. Most panels split it automatically. If yours does not, enter it as two quoted strings in the same record; resolvers join them back together.

Wait for propagation, then verify with a direct query. If the lookup returns the full key with no truncation, you are ready.

Step 3: switch signing to the new selector

Point your signing table at the new selector and key file, then reload OpenDKIM. On a hosted provider, mark the new key as active. Send a test to a mailbox you can inspect and confirm the header shows s=s202611 and dkim=pass in the Authentication-Results line.

Step 4: keep the old public key published

This is the step people skip. Messages signed with the old key are still sitting in queues, being forwarded, or waiting in mailing list digests. If you delete the old record now, those messages fail verification after the fact. Leave the old TXT record in place for at least 7 days; I usually wait 14.

Step 5: retire the old key

After the overlap window, delete the old private key from the server and any backups you can reach. For the DNS record, you have two choices. Remove it entirely, or keep the record but empty the key, publishing v=DKIM1; p= with nothing after it. An empty p= tag tells receivers the key is revoked, which is clearer than a missing record if anyone replays old mail.

DayActionCheck
Day 0Lower TTL, inventory sendersSelectors noted for each sender
Day 1Generate key, publish new TXTLookup returns the full key
Day 2Switch signing to new selectorTest message shows dkim=pass
Day 2 to 16Overlap, both keys publishedDMARC reports show no new failures
Day 16Revoke old key, delete private fileOld selector returns empty p=

The advice I disagree with: rotate every 30 days

You will find security checklists that insist on monthly DKIM rotation, sometimes automated with a cron job. For a small team running its own mail server, I think that does more harm than good.

Each rotation is a DNS change plus a signing change, and each one is a chance to publish a truncated key, forget a reload, or break a contact form that was quietly pinned to the old selector. A monthly cycle multiplies those chances by twelve, and a broken signature hurts deliverability far more reliably than an old key does. Large providers automate rotation because they have staging, monitoring and people on call. If you have none of those, a careful rotation once or twice a year, plus an immediate one after any access change, is the better trade.

Watching for problems after the switch

Your DMARC aggregate reports are the cheapest early warning you have. In the days after a rotation, look for a sudden rise in DKIM failures from your own sending IPs. That usually means one system is still signing with the old selector but you changed something about it, or the new TXT record is malformed for some resolvers.

If DKIM fails across the board, roll back by switching signing to the old selector, which is still published. That is the whole point of the overlap. While you are in DNS anyway, it is a good time to confirm your SPF record is not over its lookup budget; our guide on fixing the SPF 10 lookup limit covers that check. If you want inbound mail tightened as well, the walkthrough on setting up MTA-STS for inbound TLS pairs well with this job.

More step by step setups like this one live in our guides section.

Frequently asked questions

How often should you rotate DKIM keys?

For most small domains, once every 6 to 12 months is enough. Rotate immediately if a person with access to the private key leaves or if a server holding it is compromised. More frequent rotation only makes sense when the process is fully automated and monitored.

Can you have two DKIM keys at the same time?

Yes. Each key lives under its own selector, so a domain can publish as many as it needs. That is exactly how a safe rotation works: the old and new keys sit side by side for one to two weeks. Different sending services also commonly use separate selectors on the same domain.

Will rotating DKIM keys affect email deliverability?

Not if the new key is published and verified before signing switches over and the old key stays published during the overlap. Problems come from truncated TXT records or deleting the old key too early. Watch DMARC reports for a week afterwards to catch anything you missed.

IV
Ilkka Varis

Ilkka has run mail servers for small companies since the days of hand edited DNS zones.

More posts by Ilkka

More in Guides

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven strcoding tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto