DNS and email – Finding mail relays

DNS and email addresses often just work and we don’t have to think much about them. However, if you’re trying to set them up or debug a problem, it helps to understand how to do figure out how the mail is initially routed.

The first thing to do is to break down an email address. Everything to the right of the @ is a domain or host name, and everything to the left is a recipient at that domain or host. So for help@u.washington.edu, the mail will go to the recipient named help at the domain u.washington.edu. All recipients at a particular domain or host are normally handled by a mail relay for that domain or host. Since what’s to the right of the @ is what needs to be determined first for a message to get delivered, I’ll start by describing how to work with that.

To see how the mail gets to the point where it can be delivered to a mailbox, we need to find the first destination for mail addressed to any user at u.washington.edu. Before we can do that, however, we need to find the authoritative DNS server for that domain. If we don’t do that first step, we may not get the information we require since it may not be in the cache of the server our system is configured to query. To find the authoritative DNS server, we can use the host command to find the NS (name server) record:

% host -t ns u.washington.edu.
www.washington.edu name server marge.cac.washington.edu.
www.washington.edu name server hanna.cac.washington.edu.

Note the query for u.washington.edu had a period at the end of the domain. This assures that you’re actually talking about that domain, and not possibly a subdomain (if your system is configured with a domain search path). It’s normally fine to just pick the first server to look for the MX (mail exchange) records:

% host -t mx u.washington.edu. marge.cac.washington.edu.
Using domain server:
Name: marge.cac.washington.edu.
Address: 140.142.5.13#53
Aliases: 

u.washington.edu mail is handled by 100 mxe11.u.washington.edu.
u.washington.edu mail is handled by 100 mxe12.u.washington.edu.
u.washington.edu mail is handled by 100 mxe13.u.washington.edu.
u.washington.edu mail is handled by 100 mxe14.u.washington.edu.
u.washington.edu mail is handled by 100 mxe15.u.washington.edu.
u.washington.edu mail is handled by 100 mxe17.u.washington.edu.
u.washington.edu mail is handled by 100 mxe2.u.washington.edu.
u.washington.edu mail is handled by 100 mxe4.u.washington.edu.
u.washington.edu mail is handled by 100 mxe6.u.washington.edu.
u.washington.edu mail is handled by 100 mxe7.u.washington.edu.
u.washington.edu mail is handled by 100 mxe8.u.washington.edu.
u.washington.edu mail is handled by 100 mxe9.u.washington.edu.

You can see that there are many mail servers configured for u.washington.edu, and actually they’re mail relays, since their job is to route mail to the next destination. The number before each host’s name is the preference – lower numbers are used before higher numbers. Note that this query was done from outside of UW; a query done from within UW would have listed different hosts.

If the query returns no MX records then the host itself will receive the mail. If you’re interested in finding the address, you can use the host command without any arguments, since A (address) records are returned by default:

% host -t ns www.washington.edu.
www.washington.edu name server dnsload2.cac.washington.edu.
www.washington.edu name server dnsload1.cac.washington.edu.
% host www.washington.edu. dnsload2.cac.washington.edu.
Using domain server:
Name: dnsload2.cac.washington.edu.
Address: 140.142.10.207#53
Aliases: 

www.washington.edu has address 140.142.15.8
www.washington.edu has address 140.142.11.6
www.washington.edu has address 140.142.11.167

It should be noted that not all hosts are configured to receive mail. http://www.washington.edu falls into this category, so mail to user@www.washington.edu will fail.

While I’ve glossed over several details, the above is usually enough to correctly trace where mail will get delivered. There may seem to be a lot steps involved, but the result is usually just the first mail relay.. I’ll cover different places mail goes after the relay, as well as recipients (what’s to the left of the @) in a later post.

Leave a Reply