Choosing the RHS of Secondary MX Records

(Based on a post to comp.mail.sendmail on 18 Jul 2003.)


An important step in setting up a secondary mail server is adding a second MX (mail exchanger) record to the set of DNS records for the domain:


vmailpros.com.          1D IN MX        10 mail.vmailpros.com.
vmailpros.com.          1D IN MX        50 mail2.vmailpros.com.

In the above example, mail.vmailpros.com is the host name of the primary mail server for the domain vmailpros.com; mail2.vmailpros.com is the host name of the secondary mail server.

Most instructions for setting up MX records indicate that the name of the mail server (on the RHS [right-hand-side] of the MX record) must be the actual name of the host receiving mail. While this is a true statement, in practice if there are multiple "A" records that point to the primary mail server, any of them can appear on the RHS of the MX record in most cases.

However, for secondary, tertiary (etc.) mail servers, it is critical that the RHS of the MX record be the actual host name of the secondary server. Otherwise, you will get the infamous "mail loops back to myself" error.

What Is the Real Name of My Secondary Mail Server?

From the command line, try these:

  1. Type: hostname
  2. Type: echo '$j' | sendmail -bt
  3. If you don't like the above, try adding this to your mc file and build a new sendmail.cf:
    
    define(`confDOMAIN_NAME',`myCanonicalName')
    

    where myCanonicalName is the host name you want sendmail to use as its real name.

Scenario: Why Mail Loops When You Use the Wrong Host Name

  1. The primary mail server for the address is down.
  2. The sending client or intermediate mail server looks up the secondary server and sees that its name is dude.vmailpros.com, which resolves to the same IP address as the server whose "real" name is mail2.vmailpros.com. The mail is sent to mail2.vmailpros.com (the same server as dude.vmailpros.com.)
  3. The server mail2.vmailpros.com looks in relay-domains or access.db and sees that it relays mail for the target domain, so it accepts the mail.
  4. mail2.vmailpros.com tries to decide what to do with the mail. It first tries to contact the primary mail server, which is still down.
  5. mail2.vmailpros.com sees that dude.vmailpros.com is the secondary server. mail2.vmailpros.com looks in $j and doesn't see dude.vmailpros.com (but mail2.vmailpros.com), so it needs to use the SMTP mailer to send the mail to dude.vmailpros.com.
  6. Using the smtp mailer, mail2.vmailpros.com opens a connection to dude.vmailpros.com (which is itself!!) and sends the mail (to itself).
  7. Go to step 3 (until maximum MX loops reached, then fail).