Postfix as backup MX

Redundancy is very important these days, specially for a highly used medium such as mail. Luckily you can set up something as a “backup MX”.

Normally when person a sends a mail to person b the mail-server will search where to deliver the mail trough DNS (MX record) . When we add multiple MX records we can either perform load-balancing trough DNS or set up a secondary mail-server in case that the primary goes offline.

Here I will explain how to quickly set up a backup mail-server that will keep the mails until the primary mail-server is reachable again.

First and for all we need to create a 2nd MX record. An MX record exists out of 3 parts:

  • Domain where the mail-server is for
  • The mail-server where to send the mail to
  • The priority of this MX record

it is with this priority that we specify load-balancing or backup.

vincent@testbox:# dig +short domain-a.local MX
  10 primary.domain-a.local.
  20 secondary.domain-a.local.

The dig command shows us 2 DNS records for domain-a.local.

I assume that the mail-server primary.domain-a.local is already properly set up to receive mails. For the secondary a basic postfix installation is sufficient. All we need to do is add the following line to “/etc/postfix/”

relay_domains = domain-a.local

If you have multiple domains where you need to be a backup of just add them in the same line (comma seperated).

relay_domains = domain-a.local, domain-b.local, domain-c.local

save and exit and reload postfix

vincent@testbox:# service postfix reload

That it ! When the primary mailserver is offline mail will be sent to the next MX record according to the priority. The backup MX will accept the mail and try to send it to the primary mailserver. Untill this is successfull the backup MX will keep the mail in his queue.

Important note!
Do NOT list the relayed domains in the “mydestination” line in on the backup mailserver. When you do this a local delivery will be attempted.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.