Home » Postfix » How To Set up a Postfix Mailserver as a Backup MX (mail exchanger)

How To Set up a Postfix Mailserver as a Backup MX (mail exchanger)

This article will guide how to set up a Postfix mailserver as a backup MX (mail exchanger) for a domain condition by if the primary mail server is down or unreachable, it will accept and hold the messages in a queue until primary server to become online.
In this article we are going to set up a backup MX for the domain mydomain.com. And it’s primary MX for mydomain.com is called mail.mydomain.com (IP address, so I describe the backup MX backupmx.mydomain.com (IP address

We have created MX records for mydomain.com as below:

mydomain.com. 86400 IN MX 5 mail.mydomain.com .
mydomain.com . 86400 IN MX 10 backupmx. mydomain.com .

Here we assume that the Postfix on mail.mydomain.com is already installed and working fine.
Install and configure postfix on backupmx.mydomain.com.

#yum install postfix

After install postfix successfully on backup mx open /etc/postfix/main.cf and make following changes.

#vi /etc/postfix/main.cf
maximal_queue_lifetime = 15d
relay_recipient_maps =
relay_domains = hash:/etc/postfix/relaydomains
transport_maps = hash:/etc/postfix/transportmaps
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination
relay_domains = mydomamin.com

Note: If you have more than one domain you can add them by comma separated domain.

Then create file with name /etc/postfix/relaydomains and append your domain name.

#Vi /etc/postfix/relaydomains
mydomain.com OK

create /etc/postfix/transportmaps file and append following lines.

#vi /etc/postfix/transportmaps
mydomain.com smtp:mail.mydomain.com:25

Everytime a change have been made to either the transportmaps, or relaydomains files it is needed to run postmap to create/update the postfix database table.

#postmap /etc/postfix/transportmaps
#postmap /etc/postfix/relaydomains
#service postfix restart

You can also use the following script to update postfix database.


echo “running postmap”
postmap /etc/postfix/transportmaps
postmap /etc/postfix/relaydomains
echo “restarting postfix, to accept changes”
/etc/init.d/postfix restart
echo “done”

If everything working fine, mails should start comming in, in the mailqueue on the backup MX server
tail -f /var/log/mail.log
Note: The same procedure is also applicable for multiple domains.


I am founder and webmaster of www.linuxpcfix.com and working as a Sr. Linux Administrator (Expertise on Linux/Unix & Cloud Server) and have been in the industry from last 7 years.

One thought on “How To Set up a Postfix Mailserver as a Backup MX (mail exchanger)

  1. kaceykaawirn says:

    You need to take part in a contest for one of the most useful sites on the net.
    I most certainly will recommend this web site!

Leave a Reply

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


Time limit is exhausted. Please reload the CAPTCHA.

Categorized Tag Cloud