RFC 974 HISTORIC EMAIL · DNS · ROUTING

MX routing: Mail routing and the domain system

How a mail server uses DNS MX records to decide where to deliver a message.

On rfc-editor.org ↗
PUBLISHED
January 1986
AUTHORS
C. Partridge
STREAM
Legacy
OBSOLETED BY
RFC 2821 — SMTP
MX PREFERENCE
unsigned 16-bit integer
EMPTY MX LIST
treated as preference 0 at REMOTE
FIRST TRIED
lowest preference value
DOI
10.17487/RFC0974

RFC text

Contents
Original text · RFC Editor View on rfc-editor.org ↗
Network Working Group                                    Craig Partridge
Request for Comments: 974                 CSNET CIC BBN Laboratories Inc
                                                            January 1986

                   MAIL ROUTING AND THE DOMAIN SYSTEM


Status of this Memo

   This RFC presents a description of how mail systems on the Internet
   are expected to route messages based on information from the domain
   system described in RFCs 882, 883 and 973.  Distribution of this memo
   is unlimited.

Introduction

   The purpose of this memo is to explain how mailers are to decide how
   to route a message addressed to a given Internet domain name.  This
   involves a discussion of how mailers interpret MX RRs, which are used
   for message routing.  Note that this memo makes no statement about
   how mailers are to deal with MB and MG RRs, which are used for
   interpreting mailbox names.

   Under RFC-882 and RFC-883 certain assumptions about mail addresses
   have been changed.  Up to now, one could usually assume that if a
   message was addressed to a mailbox, for example, at LOKI.BBN.COM,
   that one could just open an SMTP connection to LOKI.BBN.COM and pass
   the message along.  This system broke down in certain situations,
   such as for certain UUCP and CSNET hosts which were not directly
   attached to the Internet, but these hosts could be handled as special
   cases in configuration files (for example, most mailers were set up
   to automatically forward mail addressed to a CSNET host to
   CSNET-RELAY.ARPA).

   Under domains, one cannot simply open a connection to LOKI.BBN.COM,
   but must instead ask the domain system where messages to LOKI.BBN.COM
   are to be delivered. And the domain system may direct a mailer to
   deliver messages to an entirely different host, such as SH.CS.NET.
   Or, in a more complicated case, the mailer may learn that it has a
   choice of routes to LOKI.BBN.COM.  This memo is essentially a set of
   guidelines on how mailers should behave in this more complex world.

   Readers are expected to be familiar with RFCs 882, 883, and the
   updates to them (e.g., RFC-973).

Mail Routing and the Domain System


What the Domain Servers Know

   The domain servers store information as a series of resource records
   (RRs), each of which contains a particular piece of information about
   a given domain name (which is usually, but not always, a host).  The
   simplest way to think of a RR is as a typed pair of datum, a domain
   name matched with relevant data, and stored with some additional type
   information to help systems determine when the RR is relevant.  For
   the purposes of message routing, the system stores RRs known as MX
   RRs. Each MX matches a domain name with two pieces of data, a
   preference value (an unsigned 16-bit integer), and the name of a
   host.  The preference number is used to indicate in what order the
   mailer should attempt deliver to the MX hosts, with the lowest
   numbered MX being the one to try first.  Multiple MXs with the same
   preference are permitted and have the same priority.

   In addition to mail information, the servers store certain other
   types of RR's which mailers may encounter or choose to use.  These
   are: the canonical name (CNAME) RR, which simply states that the
   domain name queried for is actually an alias for another domain name,
   which is the proper, or canonical, name; and the Well Known Service
   (WKS) RR, which stores information about network services (such as
   SMTP) a given domain name supports.

General Routing Guidelines

   Before delving into a detailed discussion of how mailers are expected
   to do mail routing, it would seem to make sense to give a brief
   overview of how this memo is approaching the problems that routing
   poses.

   The first major principle is derived from the definition of the
   preference field in MX records, and is intended to prevent mail
   looping.  If the mailer is on a host which is listed as an MX for the
   destination host, the mailer may only deliver to an MX which has a
   lower preference count than its own host.

   It is also possible to cause mail looping because routing information
   is out of date or incomplete.  Out of date information is only a
   problem when domain tables are changed.  The changes will not be
   known to all affected hosts until their resolver caches time out.
   There is no way to ensure that this will not happen short of
   requiring mailers and their resolvers to always send their queries to
   an authoritative server, and never use data stored in a cache.  This
   is an impractical solution, since eliminating resolver caching would
   make mailing inordinately expensive.  What is more, the out-of-date
   RR problem should not happen if, when a domain table is changed,

Mail Routing and the Domain System


   affected hosts (those in the list of MXs) have their resolver caches
   flushed. In other words, given proper precautions, mail looping as a
   result of domain information should be avoidable, without requiring
   mailers to query authoritative servers.  (The appropriate precaution
   is to check with a host's administrator before adding that host to a
   list of MXs).

   The incomplete data problem also requires some care when handling
   domain queries.  If the answer section of a query is incomplete
   critical MX RRs may be left out.  This may result in mail looping, or
   in a message being mistakenly labelled undeliverable.  As a result,
   mailers may only accept responses from the domain system which have
   complete answer sections.  Note that this entire problem can be
   avoided by only using virtual circuits for queries, but since this
   situation is likely to be very rare and datagrams are the preferred
   way to interact with the domain system, implementors should probably
   just ensure that their mailer will repeat a query with virtual
   circuits should the truncation bit ever be set.

Determining Where to Send a Message

   The explanation of how mailers should decide how to route a message
   is discussed in terms of the problem of a mailer on a host with
   domain name LOCAL trying to deliver a message addressed to the domain
   name REMOTE. Both LOCAL and REMOTE are assumed to be syntactically
   correct domain names.  Furthermore, LOCAL is assumed to be the
   official name for the host on which the mailer resides (i.e., it is
   not a alias).

Issuing a Query

   The first step for the mailer at LOCAL is to issue a query for MX RRs
   for REMOTE.  It is strongly urged that this step be taken every time
   a mailer attempts to send the message.  The hope is that changes in
   the domain database will rapidly be used by mailers, and thus domain
   administrators will be able to re-route in-transit messages for
   defective hosts by simply changing their domain databases.

   Certain responses to the query are considered errors:

      Getting no response to the query.  The domain server the mailer
      queried never sends anything back.  (This is distinct from an
      answer which contains no answers to the query, which is not an
      error).

      Getting a response in which the truncation field of the header is

Mail Routing and the Domain System


      set.  (Recall discussion of incomplete queries above).  Mailers
      may not use responses of this type, and should repeat the query
      using virtual circuits instead of datagrams.

      Getting a response in which the response code is non-zero.

   Mailers are expected to do something reasonable in the face of an
   error.  The behaviour for each type of error is not specified here,
   but implementors should note that different types of errors should
   probably be treated differently.  For example, a response code of
   "non-existent domain" should probably cause the message to be
   returned to the sender as invalid, while a response code of "server
   failure" should probably cause the message to be retried later.

   There is one other special case.  If the response contains an answer
   which is a CNAME RR, it indicates that REMOTE is actually an alias
   for some other domain name. The query should be repeated with the
   canonical domain name.

   If the response does not contain an error response, and does not
   contain aliases, its answer section should be a (possibly zero
   length) list of MX RRs for domain name REMOTE (or REMOTE's true
   domain name if REMOTE was a alias).  The next section describes how
   this list is interpreted.

Interpreting the List of MX RRs

   NOTE: This section only discusses how mailers choose which names to
   try to deliver a message to, working from a list of RR's.  It does
   not discuss how the mailers actually make delivery.  Where ever
   delivering a message is mentioned, all that is meant is that the
   mailer should do whatever it needs to do to transfer a message to a
   remote site, given a domain name for that site.  (For example, an
   SMTP mailer will try to get an address for the domain name, which
   involves another query to the domain system, and then, if it gets an
   address, connect to the SMTP TCP port).  The mechanics of actually
   transferring the message over the network to the address associated
   with a given domain name is not within the scope of this memo.

   It is possible that the list of MXs in the response to the query will
   be empty.  This is a special case.  If the list is empty, mailers
   should treat it as if it contained one RR, an MX RR with a preference
   value of 0, and a host name of REMOTE.  (I.e., REMOTE is its only
   MX).  In addition, the mailer should do no further processing on the
   list, but should attempt to deliver the message to REMOTE.  The idea

Mail Routing and the Domain System


   here is that if a domain fails to advertise any information about a
   particular name we will give it the benefit of the doubt and attempt
   delivery.

   If the list is not empty, the mailer should remove irrelevant RR's
   from the list according to the following steps.  Note that the order
   is significant.

      For each MX, a WKS query should be issued to see if the domain
      name listed actually supports the mail service desired.  MX RRs
      which list domain names which do not support the service should be
      discarded.  This step is optional, but strongly encouraged.

      If the domain name LOCAL is listed as an MX RR, all MX RRs with a
      preference value greater than or equal to that of LOCAL's must be
      discarded.

   After removing irrelevant RRs, the list can again be empty.  This is
   now an error condition and can occur in several ways.  The simplest
   case is that the WKS queries have discovered that none of the hosts
   listed supports the mail service desired.  The message is thus deemed
   undeliverable, though extremely persistent mail systems might want to
   try a delivery to REMOTE's address (if it exists) before returning
   the message. Another, more dangerous, possibility is that the domain
   system believes that LOCAL is handling message for REMOTE, but the
   mailer on LOCAL is not set up to handle mail for REMOTE.  For
   example, if the domain system lists LOCAL as the only MX for REMOTE,
   LOCAL will delete all the entries in the list.  But LOCAL is
   presumably querying the domain system because it didn't know what to
   do with a message addressed to REMOTE. Clearly something is wrong.
   How a mailer chooses to handle these situations is to some extent
   implementation dependent, and is thus left to the implementor's
   discretion.

   If the list of MX RRs is not empty, the mailer should try to deliver
   the message to the MXs in order (lowest preference value tried
   first).  The mailer is required to attempt delivery to the lowest
   valued MX.  Implementors are encouraged to write mailers so that they
   try the MXs in order until one of the MXs accepts the message, or all
   the MXs have been tried.  A somewhat less demanding system, in which
   a fixed number of MXs is tried, is also reasonable.  Note that
   multiple MXs may have the same preference value.  In this case, all
   MXs at with a given value must be tried before any of a higher value
   are tried.  In addition, in the special case in which there are
   several MXs with the lowest preference value,  all of them should be
   tried before a message is deemed undeliverable.

Mail Routing and the Domain System


Minor Special Issues

   There are a couple of special issues left out of the preceding
   section because they complicated the discussion.  They are treated
   here in no particular order.

   Wildcard names, those containing the character '*' in them, may be
   used for mail routing.  There are likely to be servers on the network
   which simply state that any mail to a domain is to be routed through
   a relay. For example, at the time that this RFC is being written, all
   mail to hosts in the domain IL is routed through RELAY.CS.NET.  This
   is done by creating a wildcard RR, which states that *.IL has an MX
   of RELAY.CS.NET.  This should be transparent to the mailer since the
   domain servers will hide this wildcard match. (If it matches *.IL
   with HUJI.IL for example, a domain server will return an RR
   containing HUJI.IL, not *.IL). If by some accident a mailer receives
   an RR with a wildcard domain name in its name or data section it
   should discard the RR.

   Note that the algorithm to delete irrelevant RRs breaks if LOCAL has
   a alias and the alias is listed in the MX records for REMOTE.  (E.g.
   REMOTE has an MX of ALIAS, where ALIAS has a CNAME of LOCAL).  This
   can be avoided if aliases are never used in the data section of MX
   RRs.

   Implementors should understand that the query and interpretation of
   the query is only performed for REMOTE.  It is not repeated for the
   MX RRs listed for REMOTE.  You cannot try to support more extravagant
   mail routing by building a chain of MXs.  (E.g. UNIX.BBN.COM is an MX
   for RELAY.CS.NET and RELAY.CS.NET is an MX for all the hosts in .IL,
   but this does not mean that UNIX.BBN.COM accepts any responsibility
   for mail for .IL).

   Finally, it should be noted that this is a standard for routing on
   the Internet.  Mailers serving hosts which lie on multiple networks
   will presumably have to make some decisions about which network to
   route through. This decision making is outside the scope of this
   memo, although mailers may well use the domain system to help them
   decide.  However, once a mailer decides to deliver a message via the
   Internet it must apply these rules to route the message.

Mail Routing and the Domain System


Examples

   To illustrate the discussion above, here are three examples of how
   mailers should route messages.  All examples work with the following
   database:

      A.EXAMPLE.ORG    IN    MX    10    A.EXAMPLE.ORG
      A.EXAMPLE.ORG    IN    MX    15    B.EXAMPLE.ORG
      A.EXAMPLE.ORG    IN    MX    20    C.EXAMPLE.ORG
      A.EXAMPLE.ORG    IN    WKS   10.0.0.1    TCP    SMTP

      B.EXAMPLE.ORG    IN    MX    0      B.EXAMPLE.ORG
      B.EXAMPLE.ORG    IN    MX    10     C.EXAMPLE.ORG
      B.EXAMPLE.ORG    IN    WKS   10.0.0.2    TCP    SMTP

      C.EXAMPLE.ORG    IN    MX    0     C.EXAMPLE.ORG
      C.EXAMPLE.ORG    IN    WKS   10.0.0.3    TCP    SMTP

      D.EXAMPLE.ORG    IN    MX    0     D.EXAMPLE.ORG
      D.EXAMPLE.ORG    IN    MX    0     C.EXAMPLE.ORG
      D.EXAMPLE.ORG    IN    WKS   10.0.0.4    TCP    SMTP

   In the first example, an SMTP mailer on D.EXAMPLE.ORG is trying to
   deliver a message addressed to A.EXAMPLE.ORG. From the answer to its
   query, it learns that A.EXAMPLE.ORG has three MX RRs.  D.EXAMPLE.ORG
   is not one of the MX RRs and all three MXs support SMTP mail
   (determined from the WKS entries), so none of the MXs are eliminated.
   The mailer is obliged to try to deliver to A.EXAMPLE.ORG as the
   lowest valued MX.  If it cannot reach A.EXAMPLE.ORG it can (but is
   not required to) try B.EXAMPLE.ORG. and if B.EXAMPLE.ORG is not
   responding, it can try C.EXAMPLE.ORG.

   In the second example, the mailer is on B.EXAMPLE.ORG, and is again
   trying to deliver a message addressed to A.EXAMPLE.ORG.  There are
   once again three MX RRs for A.EXAMPLE.ORG, but in this case the
   mailer must discard the RRs for itself and C.EXAMPLE.ORG (because the
   MX RR for C.EXAMPLE.ORG has a higher preference value than the RR for
   B.EXAMPLE.ORG).  It is left only with the RR for A.EXAMPLE.ORG, and
   can only try delivery to A.EXAMPLE.ORG.

   In the third example, consider a mailer on A.EXAMPLE.ORG trying to
   deliver a message to D.EXAMPLE.ORG.  In this case there are only two
   MX RRs, both with the same preference value.  Either MX will accept
   messages for D.EXAMPLE.ORG. The mailer should try one MX first (which
   one is up to the mailer, though D.EXAMPLE.ORG seems most reasonable),
   and if that delivery fails should try the other MX (e.g.
   C.EXAMPLE.ORG).

AI ELI5

On this page
PROBLEMOnce domain names arrived, a mailer could no longer just open a connection to the host in the address, because the domain system might point mail somewhere else or offer several routes.
MECHANISMThe mailer asks for MX records, which hold a preference number and a host name, discards unsuitable ones and tries the rest from lowest preference upward.
STATUS TODAYIt is Historic and was replaced by RFC 2821.

§1Why Mail Routing Changed

The memo explains how mailers decide how to route a message addressed to an Internet domain name, by interpreting MX resource records. It says nothing about MB and MG records, which are for mailbox names.

Before domains, a mailer could usually open an SMTP connection to the host in the address, with special cases in configuration files for hosts such as UUCP and CSNET ones. Under domains, the mailer must ask the domain system where mail for a name goes. The answer may be an entirely different host, or a choice of routes.

You used to mail a letter straight to a house. Now you first ask the post office which house really takes mail for that name.

§2MX Records

Domain servers store information as resource records (RRs). An MX RR pairs a domain name with a preference value (an unsigned 16-bit integer) and the name of a host. The lowest-numbered MX is tried first, and several MXs with the same preference have the same priority.

Mailers may also meet the CNAME RR, which says a name is an alias for a canonical name, and the Well Known Service (WKS) RR, which records the services such as SMTP that a name supports.

An MX entry says who takes mail for a name and gives a ranking number. The smallest number is the first choice.

RECORD TYPES MAILERS MEET (RFC 974)
  • MXMail exchanger — Preference value plus host name; lowest is tried first.
  • CNAMECanonical name — The queried name is an alias for another name.
  • WKSWell Known Service — Which network services, such as SMTP, a name supports.

§3Querying and Choosing Hosts

The mailer on LOCAL first queries for MX RRs for REMOTE, and the RFC strongly urges doing so every time it sends. No response, a response with the truncation bit set, or a non-zero response code are errors. A truncated answer must not be used and the query should be repeated over a virtual circuit. A CNAME answer means the query is repeated with the canonical name.

If the MX list is empty, the mailer treats it as one MX with preference 0 and the host REMOTE, and delivers there. Otherwise it may discard MX hosts whose WKS record shows no mail service (optional but strongly encouraged), and it must discard every MX whose preference is greater than or equal to LOCAL's own, if LOCAL is listed. This prevents mail loops.

The mailer is required to try the lowest-valued MX and is encouraged to continue in order until one accepts. All MXs sharing a preference must be tried before any higher one.

Ask who takes the mail, cross off any computers that cannot or should not, then try the smallest number first and work upward.

§4Loops, Caches and Special Cases

Out-of-date information is a looping risk because resolver caches only learn of table changes when they time out. The RFC rejects forcing queries to authoritative servers as impractical, and instead advises checking with a host's administrator before adding it as an MX. Answers with incomplete answer sections must not be accepted.

Wildcard records such as *.IL can route a whole domain through a relay like RELAY.CS.NET; domain servers hide the wildcard, and a mailer receiving a wildcard name in an RR should discard it. Aliases should never be used in MX data. MX processing is done only for REMOTE and is not repeated for the MX hosts, so chains of MXs do not work.

Old phone-book copies can send mail the wrong way, so people must be careful when changing entries. A relay is a helper who takes mail for a whole region.

§5Worked Examples

The RFC uses a database of four hosts, A to D at EXAMPLE.ORG. A has MXs at preference 10 (itself), 15 (B) and 20 (C). A mailer on D sending to A keeps all three and must try A first. A mailer on B sending to A must discard B and C, because B's own preference is 15 and the RFC discards every MX at or above the local one, leaving only A. A mailer on A sending to D sees two MXs with preference 0 (D and C) and may try either first.

The examples show a mailer crossing off candidates that rank at or below itself, then trying the best one left.

§6References