Site Map


Setting Up MX Records In Your DNS Information

The process of updating DNS with correct MX records for your domain seems to be a source of problems and confusion, so I've tried to provide some information here that may help you avoid some of the common pitfalls.

The Basics

MX records in a DNS "zone file" have the following structure:
destination.domain. TTL IN MX preference-number

destination.domain. The host or domain name that the MX record applies to.  This name appears after the "@" in an email address, and is normally your domain name ("") and not the name of your mail server ("").  Note that if you use the full domain name here, it must have a trailing dot (".").
TTL The DNS "time to live" value for this record.  Since your MX records don't change very much, a reasonable value for this field is 12 hours (specified as "12h" or "43200" in seconds).  Note that if your mail server uses a dynamic IP address then the DNS "A" (address) record for it should have a short TTL (60 seconds is common), but your MX records can still have a long TTL.  This field may be omitted, which case the default TTL for the zone applies.
IN Specifies that this record applies to the "internet" class of names.  This field is commonly omitted; it defaults to the type of the previous field, which is almost always "IN".
MX The type of DNS record this is.  MX == "Mail eXchanger".
preference-number A numeric value that indicates the preference that should be given to this MX record relative to other MX records that apply to the same destination domain.  Lower numbers imply higher preference. The hostname (not IP address) of a mail server that will accept mail addressed to "user@destination.domain".  If you use a fully qualified domain name here (which you must do if you're using my servers), then the name must have a trailing dot.  Note: only list a mail server here if it listens on the standard SMTP port (25).

For example, suppose that I've registered the domain name "".  I've set up a Linux machine as my mail server and called it "".  My ISP blocks port 25, so my server only listens on port 2525 and I can't list it as an MX record in my DNS information.  Instead, I've signed up for service, so I'm listing two of the servers in my DNS info and they will forward my mail to me on port 2525.

My DNS information should look something like this (I've left out the optional TTL and class fields): MX 10 MX 20

Note the trailing dots on all fully qualified names.  Note as well that the name of my mail server ( doesn't appears anywhere in this information: that's what we want, since the only servers that need to know about my mail server are mx1 and mx3.

If I switched ISPs to one that doesn't block port 25, I could update my mail server to listen on the standard port and add a third line to my MX information: MX 5 MX 10 MX 20

Other Issues

There are some other common issues that people run into:

MX records pointing to a CNAME

The hostname on the right side of an MX record (the "mail server name") must exist in DNS as an "A" record and not as a CNAME (alias) record.  For example, the following DNS information is incorrect: A CNAME MX 10 ; WRONG: "mail" is a CNAME

However, you can do something similar by creating a second "A" record for "": A A MX 10 ; OK

Don't create your own hostnames for my servers

Several people have asked if it's okay to create hostnames in their domain that refer to my server by IP address: A ; this IP is MX 10 ; Not Recommended!

I strongly recommend against creating your own hostnames for my servers.  The IP addresses associated with my servers do change, and more frequently than you might expect: load balancing, ISP renumberings and server moves all result in such changes.  If you refer to my servers using the hostnames that I provide then these changes will be transparent.  Otherwise you run the risk of delayed or even lost mail.

Mail to subdomains doesn't work

Consider the following DNS information: A A MX 10 MX 20

Mail sent to "" will be delivered to, or if mx1 is down, to  From there it will be forwarded to my mail server on "" (this forwarding is configured on mx1 and mx3, not in DNS).

However, if mail is sent to "" the two MX records above are ignored and delivery is attempted directly to "".  If there is no SMTP server listening on that host, the mail will be returned to sender.  Why?  MX records are used only when the entire "host part" of an email address (the part after the "@") matches the "destination domain" in the MX record.

So, in this example "" is not an exact match for "", so the MX records are ignored.  If you want mail for "" to also be delivered to the same servers, you need more MX records: MX 10 MX 20

Note: if you set up MX records for a subdomain that point to servers, you must let me know so I can update my configuration.  By default my servers will only deliver mail addressed to the domain itself, not subdomains.  There's no extra charge for this.

What about wildcard MX records?

A wildcard MX record is one where the "destination domain" starts with "*", as in "*".  An MX record like this means "send mail addressed to any host under to this MX server".  My experience with these is that they're usually more trouble than they're worth, and I'd recommend you consult a good DNS resource and understand the drawbacks before you use them.

How many DNS servers do I need?

I strongly recommend that you have at least two separate DNS servers for your domain.  They should be reliable, well-connected servers located on different subnets and preferably in different cities.  Otherwise you may encounter a situation where none of your DNS servers are reachable, which may cause mail to (or even from) your domain to be rejected because your domain appears invalid. has a more detailed explanation of why a solid set of nameservers is important.

I do not provide DNS services, but I'd added a few links to sites that do on my links page.

Where can I get more information about MX records or DNS in general?

I highly recommend the O'Reilly book DNS and BIND.  It's available both as a print version (mine is well used and never far from my computer) and on-line as well at the O'Reilly site.

Copyright © 2002-2010
Scott Logan