DistributedNetworks DistributedNetworks


Unix Network Admin   «Prev  Next»
Lesson 9Email and DNS
ObjectiveUse nslookup to view MX records.

Email DNS Relationship

Electronic mail relies on DNS to deliver mail properly. For example, suppose electronic mail is intended for user@corporation.com. How does sendmail determine where to send email intended for corporation.com? It obtains this answer by querying DNS for an MX (Mail Exchange) record for corporation.com. Such a record specifies the name of a machine that is equipped to handle mail directed at corporation.com.

Mail Exchange (MX) entries

Mail Exchange entries in your forward zone file redirect email for your server or for an entire domain. If you are using DNS, you must have an MX record for your server and/or domain to receive email messages.
MX records have four fields:
  1. The IN field, with which you are already familiar.
  2. The TYPE field, which for MX records is MX.
  3. A number that determines the priority of each MX entry. Lower numbers indicate a higher priority for that particular MX entry. SMTP transfer agents will try first to deliver mail to machines corresponding to MX records with lower preference numbers.
  4. The MX field, which denotes a mail exchange host.
Below are three sample MX entries:
IN   MX    0 mail.corporation.com.
IN   MX   20 mail2.corporation.com.
IN   MX   10 mail2.corporation.com.

Here is a sample zone file containing MX records:
$ORIGIN corporation.com.
marketing  IN SOA   newton.marketing.corporation.com.
	james.marketing.corporation.com.
	( 19990707 1800 300 604800 1800 )
IN NS      mail.marketing.corporation.com.
IN NS      raphael.sales.corporation.com.
IN MX  10  mail2.sales.corporation.com
IN MX   0  mail.marketing.corporation.com.
Note: Remember that $ORIGIN puts corporation.com. after KEYS in the left column, and blank fields repeat the previous key.
Notice that marketing.corporation.com has an MX record (with the preference of 0) pointing to the machine named mail.marketing.corporation.com. The sendmail program, given a message to james@marketing.corporation.com, looks up an MX record for mail.marketing.corporation.com and retrieves mail.marketing.corporation.com.
Then sendmail contacts the SMTP server on mail and delivers the message there.
In this case, the MX entry with a 0 gets priority and will send mail for the marketing subdomain. If this action fails, sendmail will query the next MX record (mail2), then any CNAME and A records, in that order.

mail queue

When sendmail approves the MX entry, it lines up messages for sending. It converts the message to its internal form and stores it in a queue directory. The directory locations change, depending upon your flavor of UNIX. Linux, for example, uses /var/spool/mqueue. SunOS and Solaris systems use /usr/spool/mqueue.
You may examine the contents of the mail queue by using the mqueue command. This enables you to see which messages are awaiting delivery by sendmail.

Viewing mxRecords - Exercise

Click the Exercise link below to use the nslookup program to view MX records.
Viewing mxRecords - Exercise
DNS: Domain Name Service (DNS) is an Internet-wide service for converting numeric IP addresses to host names and back.