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 @example.com

Therefore there is a mail server called mail.example.com.

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

mail.example.com receives all email for @example.com to make this work we had to setup a DNS entry alike

example.com.             IN      MX      10 mail.example.com

mail. example.com.        IN      A       192.168.10.10

Add an additional entry to the DNS server for the second MX record, if you name your backup mail server  backupmail.example.com

example.com.             IN      MX      20 backupmail.example.com

backupmail. example.com.          IN      A       192.168.10.20

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

Or

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/sendmail.cf

[root@backupmail ~]# vim etc/mail/sendmail.cf

Find the following section:

# SMTP daemon options

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

DaemonPortOptions and then modify it so it looks like this:

O DaemonPortOptions=Port=smtp,Addr=0.0.0.0, 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 example.com domain

Ask sendmail to receive emails for example.com

Open the access file:

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

Append  the following line to this file

To:example.com              RELAY

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

Save exit

Tell sendmail how to send it to the final recipient

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

Append the following line

example.com    smtp:mail.example.com

Make sure there is no extra space in the line and only a tab between example.com<TAB>smtp:mail.example.com

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 sendmail.mc from sendmail.cf

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

type

[root@backupmail ~]# dig example.com mx

And we are looking for something like this

example.com.           38400   IN      MX      10 mail.example.com.

example.com.           38400   IN      MX      20 backupmail.example.com.

check mail server

[root@backupmail ~]# telnet backupmail.example.com 25

You will receive a response like this

Trying 192.168.10.20…

Connected to backupmail.example.com(192.168.10.20).

Escape character is ‘^]’.

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

Type:

ehlo root

and the server will respond with

250- to backupmail.example.com Hello [192.168.10.20], pleased to meet you

250-ENHANCEDSTATUSCODES

250-PIPELINING

250-8BITMIME

250-SIZE

250-DSN

250-ETRN

250-DELIVERBY

250 HELP

Type:

mail from:root@localost

server will respond with:

250 2.1.0 root@localost… Sender ok

Type:

rcpt to:saad.faruque@stonehill.in

server will respond with:

250 2.1.5 root@stonehill.in… Recipient ok

Type:

data

server will respond with:

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

Type:

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

Advertisements

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:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s