SuperGeekery: A blog probably of interest only to nerds by John F Morton.

A blog prob­a­bly of inter­est only to nerds by John F Mor­ton.

Untangling MX: Setting up DNS records for a web site with different mail server.

Dns_Tangle_640X200

I recent­ly had to set up an MX record for a client and although I’ve set them up before, it sud­den­ly made sense to me in a way that it hadn’t before. Per­haps my sto­ry will help some­one else have a sim­i­lar epiphany.

Basic name serv­er set up.

My client had their site and their mail all han­dled by the same serv­ing com­pa­ny. This meant their name serv­er records were basic. There were 3 entries and that was it. All traf­fic to their domain used the same records. It could be web traf­fic or mail traf­fic. It didn’t mat­ter. They were some­thing like this. (I’m using dum­my’ URL names in this post, like myname​serv​er​.com and my​.domain​.com. Don’t take those lit­er­al­ly. Use your own info where appro­pri­ate.)

ns1.mynameserver.com
ns2.mynameserver.com
ns3.mynameserver.com

The prob­lem. #

My client came to me because their site was painful­ly slow. Their host­ing plan was a shared host­ing plan and their site traf­fic demand­ed had out­grown what the serv­er was able to han­dle. Their site need­ed to be on a ded­i­cate, robust serv­er. I did some research and pre­sent­ed them with a rec­om­men­da­tion, got their sign off, and moved the site suc­cess­ful­ly. (The site was an Expres­sion Engine site. I moved it to Engine Host­ing. That’s not real­ly that impor­tant to what I’m going over here though.)

The tricky part of the move was that they were not ready to move their mail to a new serv­er. It need to stay where it was. That meant going from an easy” DNS set up, to a more com­plex set up. I had to split the MX (Mail Exchange) records off from the reg­u­lar DNS records.

You might won­der why there was no MX record to begin with and how the email still man­aged to get to its des­ti­na­tion in the old set­up. Although I knew it worked, I nev­er both­ered to ask why. I found an arti­cle on MX records on Wikipedia that had the answer.

If no MX records were present, the serv­er falls back to A, that is to say, it makes a request for the A record of the same domain.”

If I only set up the DNS the easy way, an email mes­sage falling back to the A records would mean that mes­sage would be deliv­ered to the new serv­er where the web site was host­ed, and not the old serv­er where the mail was sup­posed to be han­dled. I need­ed to split the traf­fic by set­ting up an advanced DNS record.

Advanced DNS record set­ting. #

The domain name was reg­is­tered with Net­work Solu­tions. The abil­i­ty to set the MX record sep­a­rate­ly from the oth­er records in the Net­work Solu­tion inter­face is called Advanced DNS Set­tings. Oth­er reg­is­trars allow you to do this as well though.

The Advanced DNS Set­tings choice means Net­work Solu­tions will use their name servers, for exam­ple, NS43.WORLD​NIC​.COM. You need to man­u­al­ly set up the traf­fic behind that name serv­er.

The A records #

I don’t want to spoil the sur­prise end­ing of this post, but here’s a screen­shot of where I need­ed to get to. It might help as I go through the nit­ty grit­ty.

Proper DNS set up for separate MX and A records.

I had to dig into the meat of the DNS records a bit more and set the A record (the main DNS record) and the MX record man­u­al­ly. For the A record I need­ed the actu­al IP of the serv­er the site would even­tu­al­ly live on.

You can find this out the IP address of the A record with a dig’ com­mand from the Ter­mi­nal on a Mac. (Win­dows folks, I’m not sure how to exe­cute these com­mands on your plat­form. I’m sure there is a way though.)

Below is the com­mand I would put into my Ter­mi­nal. I’m exe­cut­ing a dig’ ask­ing for the A’ record from my site’s name serv­er, ns1​.dreamhost​.com, and spec­i­fy­ing the domain I’m ask­ing about, supergeek​ery​.com. I also spec­i­fy I just want the short’ answer. Don’t over­look the at’ sym­bol, the @, before the name serv­er.

dig A @ns1.dreamhost.com supergeekery.com +short

The result of this com­mand is my IP address for SuperGeek​ery​.com. That’s what needs to go into the A record, in essence what the name serv­er trans­lates the word supergeek​ery​.com’ into for com­put­ers to locate the serv­er with it’s request for infor­ma­tion.

NOTE: I had already set up the new serv­er to expect the traf­fic. Although I didn’t test this dig com­mand before I set up the serv­er, I wouldn’t expect the dig com­mand to work until that is done. Want to know more about the dig’ com­mand? Check out this great arti­cle on dig. https://​www​.mad​boa​.com/​g​e​e​k​/dig/

I used that IP address for the www’ record, the ‘@’ and the ‘’. That let a URL star­ing with www’ point to the right domain, a URL that didn’t start with any­thing (ie, no www’ in front of the domain name), and a ‘’, to let any­thing unspec­i­fied to go to the IP address, ie mysub​do​main​.mydo​main​.com.

One more A record #

So the A records are set up. How do you set up the MX record? I incor­rect­ly assumed I could use the IP address of the orig­i­nal serv­er for this. The MX record need­ed to be a CNAME, a canon­i­cal name. A numer­ic IP won’t work here. So what CNAME should you place in the MX record field? It has be be cre­at­ed man­u­al­ly.

From every­thing I’ve read, there isn’t a rule to fol­low as what you choose for the name, but it does seem to be com­mon to use mail’ as the sub­do­main you’ll set up for this. This means you’ll be cre­at­ing mail​.mydo​main​.com’ as an A record before you use it as your MX record.

First, cre­ate anoth­er A record, just like cre­at­ing the www’, ‘@’, and ‘*’ records. This time use mail’ instead, which cre­ates the A record for mail​.mydo​main​.com’. In the place where the numer­ic IP address is asked for, this time use the server’s IP address where the mail is processed. In my case, this was the IP address of the old serv­er for mydo​main​.com.

Final­ly, the MX record gets made. #

Don’t stop here though. The MX record isn’t cre­at­ed yet. If you’re in Net­work Solu­tions, you have a but­ton called Edit MX Records”. Oth­er reg­is­trars will have some­thing sim­i­lar. The MX record needs to be the same as the A record that was just cre­at­ed that points to the IP address for the mail serv­er. In this case, it’s mail​.mydo​main​.com’, so put that into your MX record. (Take a look at the screen­shot from Net­work Solu­tions I’ve added to this blog post. Notice mail​.mydo​main​.com’ appears twice in that screen­shot.)

Now email to the mydo​main​.com serv­er will check the MX record and see the address mail​.mydo​main​.com which is point­ing to the cor­rect IP for your serv­er, which is dif­fer­ent from the web host. Whew!

QR code for the Untangling MX: Setting up DNS records for a web site with different mail server.

Link to this page