Internet · Linux · Making things work · Networking · Open Source · Work

Setting up backup mail exchange server with sendmail

Setting up backup mail exchange server with sendmail

Most systems admin is used to setting up the primary mail server, but many of them (like me) are not used to setup a backup mail server in a regular basis. This is my attempt to create a complete document on setting up a backup mail server and testing it for the dooms day. (Actually it in used more often than you can think of)

Lets say we have mail server for

Therefore there is a mail server called

Mail and dns works hand in hand. DNS server tells where to deliver the email. MTA always looks for DNS entry to find the primary and secondary mail server incase the primary is not reachable. So the first thing we need to do it setup a DNS entry for the backup mail server

Check the diagram to visualize what we are trying to achieve

backup-mail-server mail, sendmail, backup, mailserver, mailertable, access, access.db, mailertable.db, mx, backup mx,  syntax, telnet

Setup DNS receives all email for to make this work we had to setup a DNS entry alike             IN      MX      10

mail.        IN      A

Add an additional entry to the DNS server for the second MX record, if you name your backup mail server             IN      MX      20

backupmail.          IN      A

Setup mail relay server in sendmail

I am still used to working with sendmail, never got myself moving into postfix

Install sendmail

If you are in redhat or a clone distribution you can install

[root@backupmail ~]# yum install sendmail


If you already have it installed, update it

[root@backupmail ~]# yum update sendmail

Always a good practice to update your sendmail and related packages, thought they are relatively stable and secured compared to the bad old day.

Make sure sendmail is on in reboot

[root@backupmail ~]# chkconfig sendmail on

Open up sendmail

Open /etc/mail/

[root@backupmail ~]# vim etc/mail/

Find the following section:

# SMTP daemon options

O DaemonPortOptions=Port=smtp,Addr=, Name=MTA

DaemonPortOptions and then modify it so it looks like this:

O DaemonPortOptions=Port=smtp,Addr=, Name=MTA

This will enable sendmail to listen in smtp port 25 in all available IP address for the server.

Now we got the sendmail server up and running

We need to tell the mail server to receive email for domain

Ask sendmail to receive emails for

Open the access file:

[root@backupmail ~]# vim /etc/mail/access

Append  the following line to this file              RELAY

Make sure there is no extra space in the line and only a tab between<TAB>RELAY

Save exit

Tell sendmail how to send it to the final recipient

 [root@backupmail ~]# vim /etc/mail/mailertable

Append the following line

Make sure there is no extra space in the line and only a tab between<TAB>

Save exit

Update all db and configuration files

Most of the files we updated are source files for db and configurations. Make sure to run

[root@backupmail ~]# cd /etc/mail

[root@backupmail mail]# make clean

[root@backupmail mail]# make

This will rebuild from

access.db from access

and mailertable.db from mailertable

[root@backupmail mail]# services sendmail restart

How will it work

Your backupmail server is ready to receive the mail. As soon as the dns database is updated, your primary mail server/link is not available, any internet mail server will try to get in touch with your backup mail server to deliver the email.

The backup mail server will receive the email and wait for the primary mail server to be up and deliver it for local delivery.

Let’s check it

Mail and dns works hand in hand. DNS server tells where to deliver the email

Check dns for MX record


[root@backupmail ~]# dig mx

And we are looking for something like this           38400   IN      MX      10           38400   IN      MX      20

check mail server

[root@backupmail ~]# telnet 25

You will receive a response like this


Connected to

Escape character is ‘^]’.

220 ESMTP Sendmail 8.13.8/8.13.8; Wed, 2 May 2012 16:18:23 +0530


ehlo root

and the server will respond with

250- to Hello [], pleased to meet you








250 HELP


mail from:root@localost

server will respond with:

250 2.1.0 root@localost… Sender ok



server will respond with:

250 2.1.5… Recipient ok



server will respond with:

354 Enter mail, end with “.” on a line by itself


hello world

this is a test mail


server will respond with:

250 2.0.0 q42AmNfD028908 Message accepted for delivery

Check your mail mail server for the message to confirm the message was delivered successfully.

Do NOT use the mail domain inside local-host-names file or anywhere else to indicate the backupmail server is the final recipient of the email. This will make the mail server try to deliver the email locally and as recipients are not present shall bounce the email and the mail will never reach the destination.

Tag: mail, sendmail, backup, mailserver, mailertable, access, access.db, mailertable.db, mx, backup mx,  syntax, telnet


2 thoughts on “Setting up backup mail exchange server with sendmail

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s