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:          1D IN MX        10          1D IN MX        50

In the above example, is the host name of the primary mail server for the domain; 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

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