MX backup with a friend

You just finished setting up your MX server and everything works fine. And now you are wondering whether you need a secondary MX server for backups. Some would say that these days you actually don’t need a secondary MX server, because MTAs (mail transfer agent) queue mail if MX server is down. In addition a secondary MX server might be abused by spammers. But just for fun, let’s assume you want to have a backup MX server. And you are lucky enough to have a friend who also runs an MX server which he is willing to configure as your backup server.

Let’s say your mail server is and your friend’s on which you both run postfix as MTA.

DNS MX records

First make sure that DNS records are correct. You both need to set up DNS records to have secondary MX records point to each other:   A        MX   0        MX   10   A        MX   0        MX   10

Postfix relay and transport

Postfix allows to set up mail relaying. It can be used to relay friend’s emails if a request comes to server which would happen if is down. In that case Postfix queues a message and retries to relay it later to

Just update postfix to allow mail relay to with a proper transport (no MX lookup, see below). Add following lines to /path/to/postfix/

relay_domains =
transport_maps = hash:/path/to/postfix/transport

Make sure that is not listed in virtual_maps and mydestination.

You also need to overwrite default relay transport in /path/to/postfix/transport to avoid DNS loops (when primary MX server is not available and mail is relayed to a secondary MX which is the same host): smtp:[]

Brackets [] disable MX DNS lookup hence the mail for is relayed to A record of

Postfix queue

In this set up if is down then a secondary MX server, which is, would be used. Postfix on would try to relay mail, but since the destination host is down it would queue it for later delivery.

By default, postfix keeps such mail for 5 days, but it can be increased using option bounce_queue_lifetime = 10d.

comments powered by Disqus