Domain Name System
Domain Name System is a network distributed key-value database that acts like a phone book for the Internet. The most common function is to map easy-to-remember domain and host machine names into numerical IP addresses, though many other pieces of information can be found through DNS. The DNS is a collection of zones that link to form a tree. Each zone consists of a collection of resource records (RR) that specify at the very least the start-of-authority (SOA) record and responsible name servers (NS) records. Typically, there are also A, AAAA, CNAME, and MX records. There are several RFCs that have extended DNS with new resource record types. The resource records listed below are those of interest with respect to mail services.
A or AAAA Records
A name record used to map a domain or host name into an IPv4 or IPv6 address. An A or AAAA record is often referred to as the forward lookup and is the opposite to a PTR record discussed below. See RFC 1035, 3596. A single host name can have many A and/or AAAA records, referred to as a multi-homed host.
A name pointer record used to map a numerical IPv4 or IPv6 address into a host name. A PTR is often referred to as the reverse lookup and is the opposite to an A or AAAA record. See RFC 1035. PTR records are created by the Internet Service Provider (ISP) or Autonomous System (AS) owner that supplies a customer organisation's Internet connectivity or hosting service, since they are responsible for IP address allocation within their AS. Some ISPs allow their customers to manage their own PTR records through an online administration web site.
Why Is PTR Important?
The first useful piece of information a server knows about a client connection is the IP address. Assuming a PTR record exists, the server can find the name of the connecting host through a reverse lookup using the IP address:
# dig +short -x 220.127.116.11 mail1-ec2.fsl.com.
However, anyone controlling a block of IP addresses can make a PTR record with any domain they want. So the server, using the name given by the PTR record, can then perform a forward lookup to find the A/AAAA record(s):
# dig +short A mail1-ec2.fsl.com 18.104.22.168
Since it is harder to fake A/AAAA records of a domain you don't control, when the reverse and forward lookups match, we have more confidence that the client connection is who they appear to be, as it takes two parties to agree on the A/AAAA and PTR mapping.
Without a PTR record for an IP address, this basic form of authentication would not be possible. In addition if the domain of a sender, as given by a SMTP MAIL FROM command, corresponds with the client connection's domain, then you have a stronger association and trust. SPF takes this a step further, by documenting approved mail sources for sender domains. However, the A/AAAA > PTR > A/AAAA relationship is very important cross-check in detecting falsified host names.
A mail exchange record that specifies where mail destined for a domain name should be sent. Note that a MX record only denotes the host responsible for receiving mail, not necessarily the sender of mail (see SPF) . In small organisations a MX host may handle both inbound and outbound mail traffic, while larger organisations, such as a university or ISP, will typically separate the inbound and outbound activities across clusters of hosts. See RFC 1035 and 5321 section 3.6.
A MX record references a host name, which in turn references an A and/or AAAA record. It never references an IP address directly.
example.com. IN MX 10 gandalf.example.com. gandalf.example.com. IN A 192.0.2.1
Given a mail address like firstname.lastname@example.org, a mail transfer agent (MTA) would query the DNS for MX records belonging to example.com and then perform a second query for a MX host's A and/or AAAA records. RFC 5321 section 5.1 explains the connection strategy based on MX preferences.
Implicit MX 0 Rule
Mail can be directed to a specific host, rather than a domain name. For example, email@example.com. However, a host connected to the internet does not have an MX record. RFC 5321 section 5.1 describes the special case when no MX records exist, in which case a DNS query is made for matching A and/or AAAA records corresponding to a target name, ie. gandalf.example.com.
IP Domain Literal
It is possible to bypass DNS MX records and direct mail to a specific host without specifying a domain or host name. One can use an IP domain literal eg. firstname.lastname@example.org or john@[2001:db8::1234]. Here the square bracket notation specifies an IPv4 or IPv6 address of the destination host.
A name record that maps onto another name, which allows a host to have one or more aliases. CNAME is typically used in conjunction with A or AAAA records.
gandalf.example.com. IN A 192.0.2.1 www.example.comm. IN CNAME gandalf.example.com. mail.example.com. IN CNAME gandalf.example.com.
- RFC 1034 Domain Names - Concepts And Facilities
- RFC 1035 Domain Names - Implementation And Specification
- RFC 3596 DNS Extensions to Support IP Version 6
- RFC 4408 Sender Policy Framework (SPF) for Authorizing Use of Domains in E-Mail, Version 1
- Wikipedia DNS Zone File overview.
- IANA Domain Name System (DNS) Parameters