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.
MX records in a DNS "zone file" have the following structure:
For example, suppose that I've registered the domain name "example.com". I've set up a Linux machine as my mail server and called it "smtp.example.com". 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 domainMX.net service, so I'm listing two of the domainMX.net 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):
Note the trailing dots on all fully qualified names. Note as well that the name of my mail server (smtp.example.com) 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:
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:
However, you can do something similar by creating a second "A" record for "mail.example.com":
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:
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:
Mail sent to "email@example.com" will be delivered to mx1.domainMX.net, or if mx1 is down, to mx3.domainMX.net. From there it will be forwarded to my mail server on "mail.example.com" (this forwarding is configured on mx1 and mx3, not in DNS).
However, if mail is sent to "firstname.lastname@example.org" the two MX records above are ignored and delivery is attempted directly to "server.example.com". 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 "server.example.com" is not an exact match for "example.com", so the MX records are ignored. If you want mail for "server.example.com" to also be delivered to the same domainMX.net servers, you need more MX records:
Note: if you set up MX records for a subdomain that point to domainMX.net 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 "*.example.com". An MX record like this means "send mail addressed to any host under example.com 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.
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.