Copyright © 2002-2005 by Doug Barton, dougb@dougbarton.net All rights reserved.
What is an MX record?
When a remote site on the internet wants to send someone at your domain an
e-mail message, their mail server software uses the global DNS system to look up the hostname
of the appropriate mail server to receive that mail. This type of record is referred to
as an "MX," "Mail Exchanger" or "Mail Relay" record.
The response that the remote
server gets tells it where to send the mail so that it will be relayed to you.
Is an MX record the same as the server I download my mail from?
When your site has received e-mail it is stored for you by your e-mail server.
In order to retrieve your mail from the server you need to use an interface between
your mail program (like Eudora or
Thunderbird) and the mail
server itself. This interface is usually a piece of software like POP
(the Post Office Protocol)
or IMAP. The hostname that you use to access the POP or IMAP server might be the same
as your MX record, or it might be different. The MX record's only job is to tell other
sites where mail for you should be sent. You retrieving your mail is a completely
separate operation from the standpoint of the DNS.
What is the proper format for an MX record?
The documents commonly referred to as "RFC's" (Request For
Comment) define the standards for all things related to the internet, including the
global DNS system. A very handy reference to these documents can be found
at The RFC Editor.
EXCHANGE A <domain-name> which specifies a host willing to act as a mail exchange for the owner name.
MX records cause type A additional section processing for the host specified by EXCHANGE. The use of MX RRs is explained in detail in [RFC-974].
Searching for either NS or MX records causes "additional section processing" in which address records associated with the value of the record sought are appended to the answer. This helps avoid needless extra queries that are easily anticipated when the first was made.
Additional section processing does not include CNAME records, let alone the address records that may be associated with the canonical name derived from the alias. Thus, if an alias is used as the value of an NS or MX record, no address will be returned with the NS or MX value. This can cause extra queries, and extra network burden, on every query.
podunk.xx. IN MX mailhost
mailhost IN CNAME mary
mary IN A 1.2.3.4
[RFC 1034] in section 3.6.2 says this should not be done, and [RFC 974] explicitly states that MX records shall not point to an alias defined by a CNAME. This results in unnecessary indirection in accessing the data, and DNS resolvers and servers need to work more to get the answer.
Taken together, these definitions describe a format that includes a preference value which tells remote servers what order in which to try the mail relay servers for your domain, and the hostname of the mail server itself. You may have more than one MX record for a given hostname, and you may have more than one at the same preference level.
It is extremely important that the hostname for the mail server not be a CNAME record, for the reasons described above in the reference from RFC 2181. The point that excerpt is making is that there are some sites (perhaps many sites) that will not be able to send you mail if your MX records point to CNAME's. Additionally, even if it does happen to work, you are causing additional (and unnecessary) DNS traffic by configuring records in this manner.
Are there other considerations?
Current best practices have a few additional things to be aware of when configuring
MX records. While one machine may have more than one hostname and/or IP address that it
answers to, the MX record should point to the hostname that the mail server software knows
itself as. This is a configuration option for the mail software, and is usually the same
name as the name of the machine itself. Also, many sites are installing software that prevents
their site from being used by unauthorized persons to send e-mail. One of the tests that
software uses to determine if a remote site is "legitimate" or not is to first
look up the IP address for the hostname of the mail server, then look up the hostname using
that IP address and see if they match. If they do not match, many sites will refuse to
send the mail.
From Page 6, Section 2.4 of RFC 1912
[The use of] chained records such as CNAME's pointing to CNAME's may make administration issues easier, but is known to tickle bugs in some resolvers that fail to check loops correctly. As a result some hosts may not be able to resolve such names.Having NS records pointing to a CNAME is bad and may conflict badly with current BIND servers. In fact, current BIND implementations will ignore such records, possibly leading to a lame delegation. There is a certain amount of security checking done in BIND to prevent spoofing DNS NS records. Also, older BIND servers reportedly will get caught in an infinite query loop trying to figure out the address for the aliased nameserver, causing a continuous stream of DNS requests to be sent.
Why is the proper format so important?
There are two parts to this answer, the most obvious one having already been addressed,
namely that without the proper format the chances of your mail being delivered properly go
down. As the abuse prevention systems that check for proper format become more and more common
your chances for having the mail delivered properly go down even more. The other part of
this answer is less obvious however. If you have improperly formatted MX records and remote
sites are not able to send you mail, chances are you will never know. There are
many sites that simply discard undeliverable mail and never attempt to find an alternate
contact address to let you know that your e-mail is not being delivered.
Can I have an MX record for a host that points to itself?
The simple answer to this question is yes. While the default for attempting mail
delivery for a host with no MX records is to try delivering to the host itself, there
is nothing wrong with adding an explicit MX record for the host, and in fact adding
this record will help some less-compliant MTA's get the mail to the right place.