Two mx records for two different mail servers in the same domain?

36,539

Solution 1

This should do it:

@     3600 IN A    12.12.12.12    ; irrelevant for mail routing

@     3600 IN MX 1 smtp.example.com.
smtp  3600 IN A    13.13.13.13

relay 3600 IN MX 1 relay.example.com.
relay 3600 IN A    14.14.14.14

Notes:

  • The last MX record is not strictly required (according to the standards, if there is no MX record for a domain then its A record is tried as a fallback - but some MTAs might not like that)
  • Don't forget the terminating dot at then end of fully qualified records in your zonefile!

To avoid confusion, here a clarifying variant that would send all mail targeted at @subdom.example.com to the MTA relay.example.com:

subdom 3600 IN MX 1 relay.example.com.
relay  3600 IN A    14.14.14.14

Solution 2

Of course, yes. A domain can have as many MX records (and thus, mail servers) as you wish. You can even set up priorities between them. For example, the MX records of the domain gmail.com are (you can get this a command host -t MX -v gmail.com):

gmail.com.              3547    IN      MX      5 gmail-smtp-in.l.google.com.
gmail.com.              3547    IN      MX      10 alt1.gmail-smtp-in.l.google.com.
gmail.com.              3547    IN      MX      20 alt2.gmail-smtp-in.l.google.com.
gmail.com.              3547    IN      MX      30 alt3.gmail-smtp-in.l.google.com.
gmail.com.              3547    IN      MX      40 alt4.gmail-smtp-in.l.google.com.

The outer mail servers trying to deliver mail to your domain are expected to follow the priorities in ascending order. Same priorities means redundancy (although it isn't really good on my experience).

In this example, the first try will be gmail-smtp-in.l.google.com., the second alt.gmail-smtp-in.l.google.com, and so on. The priorities are in before the last column.

Some similar can you set up in your domain. In your place I did it as a secondary mail server, for backup purposes if the first isn't really working.

Share:
36,539
meksof
Author by

meksof

Network engineer, system administrator, interested in network security and linux environment.

Updated on September 18, 2022

Comments

  • meksof
    meksof over 1 year

    I have a domain named example.com. I want to set two mail servers on this domain. The main purpose to set these mail servers is to have two different mail server, as if we have two different domains => so it is not one main server and the other one for backup.

    An MX record for domain example.com is already existing (all mails sent to [email protected] are delivered to smtp.example.com), so we have

    @   3600    IN  MX  1   smtp.example.com
    

    The A records are set like this:

    @   600 IN  A   12.12.12.12
    smtp    3600    IN  A   13.13.13.13
    relay   3600    IN  A   14.14.14.14</pre>
    

    Can we add new MX records for the second mail server?

    For example, we set up a new subdomain relay.example.com that points to our new mail server (at ip 14.14.14.14). So that all mail that are sent to [email protected] will be sent to relay.example.com.

    • MadHatter
      MadHatter over 9 years
      Are you asking if email to foo.example.com can be directed to, and received by, a different server from that which handles email to example.com? If so, the answer is yes.
    • meksof
      meksof over 9 years
      @MadHatter For example if I send an email to [email protected] it will be delivered to user at the relay.example.com(14.14.14.14) mail server, same thing for sending and receiving
    • meksof
      meksof over 9 years
      @MadHatter I added a new MX record like this: relay 3600 IN MX 10 relay.example.com
    • meksof
      meksof over 9 years
      @MadHatter But the problem here is when I send a mail from google for example to [email protected] it will be delivered to smtp.example.com
  • meksof
    meksof over 9 years
    Thx for your help, I have changed the subdomain, to avoid confusion and now it delivers mails from gmail user to [email protected] on the second mail server (relay.example.com)
  • meksof
    meksof over 9 years
    thx for your help, but making a backup mail server is not my main purpose
  • peterh
    peterh over 9 years
    @meksof Maybe you didn't read my answer enough carefully. ("Same priorities means redundancy")
  • MadHatter
    MadHatter over 9 years
    Glad you got your answer, but it seems like we might've got there a lot quicker if you hadn't redacted the domain name in question. For future questions like this, please very seriously consider not redacting.