How to Configure a VPS as a Backup Mail Server

(Based on a post to the ProviderTalk mailing list 16 Jul 2003.)


There are many ways of configuring a VPS (version 1) as a backup mail server. Here is probably the easiest. With this configuration, if the primary mail server is down or unreachable, the mail is sent to your VPS (the backup), which queues the mail and periodically (every 15-30 minutes, depending on the configuration) tries to forward it to the primary mail server.

In the simplest case, where your VPS is the primary mail server and you want to make it the secondary instead, it might be as simple as:

  1. change the DNS MX records (and wait for changes to propagate),
  2. remove the domain name from ~/etc/local-host-names,
  3. add the domain name to ~/etc/relay-domains

... and you're done.

But [sigh] it probably isn't that easy, especially if you have never vinstalled sendmail before. In that case, read and follow these steps:

  1. Verify that the new primary mail server is up and running and that the DNS MX changes have propagated through the Internet. The output of "dig mx domain.com" should point to the new primary mail server on the right-hand-side, something like:
    
    ;; ANSWER SECTION:
    vmailpros.com.          1D IN MX        10 mail.vmailpros.com.
    

    (In the example, mail.vmailpros.com is the new primary mail server.)

    Also verify that no one from the domain needs their old POP/IMAP mailboxes on your VPS.

  2. Remove domain.com from your ~/etc/local-host-names file and (possibly) from any lines that begin "Cw" in your sendmail.cf file.
  3. Check to see if your sendmail.cf file has a line that begins "CR" and that mentions the file /etc/relay-domains. (All vinstalled sendmail.cf's generated from mc files have one of those lines.) If your sendmail.cf doesn't have such a line, do the following, on the VPS (otherwise skip to step 5):
    1. Issue the command "cd"
    2. Issue the command "vinstall sendmail"
      (The vinstall sendmail command places some sendmail.cf files in the directory ~/usr/local/sendmail/cf/cf).
    3. Issue the command "cd usr/local/sendmail/cf/cf"
    4. Issue the command "ls -l"
    5. Choose one of the files ending "cf" as your sendmail.cf file:
      • If you have never before changed your sendmail.cf, choose: default.cf (skip to step 4)
      • If you have vinstalled procmail and/or SpamAssassin already, choose "default-procmail-lda.cf" or "default-procmail-lda-auth-only.cf". (The first supports pop-before-smtp-relay [the default on VPS1]; the second supports SMTP Authentication only.)
      • If you don't use procmail or spamassassin, and know that you use SMTP Authentication only, then choose the file "default-auth-only.cf"
  4. Copy the cf file selected in step 3 (first, backing up your existing sendmail.cf). Issue the commands:
    
    cp ~/etc/sendmail.cf ~/etc/sendmail.cf.old
    cp ~/usr/local/sendmail/cf/cf/<cf_file_name> ~/etc/sendmail.cf
    

    (Where <cf_file_name> is the name of the cf file you selected in step 3)

  5. Edit the (probably new) file named ~/etc/relay-domains

    Add a line that is the name of the domain that you are the back-up mail server for. (The relay-domains file is the same format as local-host-names--one domain per line. The relay-domains and local-host-names files are mutually exclusive--domain names shouldn't be listed in both files.)

  6. Verify that your VPS doesn't think it is the primary mail server for the new domain by issuing the command:
    
    echo '$=w' | virtual sendmail -bt
    
    (In the resulting output, the name of the domain for which you are the backup mail server should not appear!! If it does, go to step 7. Otherwise, go to step 8.)
  7. Type the command: hostname

    If the result is the name of the domain for which you are the backup mail server, you will have to rename your server. (There are workarounds, but they aren't worth the hassle. If you can't find how to rename the server in the backroom, contact support.)

  8. Finally, add a second MX record for the domain, listing your VPS as the secondary MX server:
    
    vmailpros.com.          1D IN MX        50 mail2.vmailpros.com.
    

    In the above example, mail2.vmailpros.com is the backup mail server on the VPS. It should be changed to reference your VPS.

    Important: The name of the backup mail server in the MX record (mail2.vmailpros.com in the example) must be the real host name of your VPS! It can't be an alias or CNAME for your VPS. Type "hostname" and see what your host name is, then supply that as the host name on the right-hand-side of the new MX line. Failure to use your VPS's real name can result in MX loops.