Skip to Content

How DNS MX lookup Works?

MX Lookup means to perform the MX Record Lookup in the DNS. It is used to check the MX Record to find the internal & external mail servers for a particular domain.

MX Record

The DNS MX record is a DNS record that routes the email to the correct email server.

The MX record tells which mail server is responsible for receiving the emails related to a particular domain and sending an email message to a route following the Simple Mail Transfer Protocol.

Purpose of MX record

The process of querying the MX record is simple: when the user sends an email address. The MTA (Message Transfer Agent) software starts sending the query to identify the MX record. If the MX record exists, it establishes an SMTP (Simple Mail Transfer Protocol) connection with those mail servers, as per their priority hierarchy.

Boost Your Website Speed!

If you want your website to run as fast as ours, consider trying Cloudways. Their powerful cloud infrastructure and optimized stack deliver exceptional performance. Free migration!

Multiple MX records

Suppose there are two MX records for domain example.com.

10 mail1.example.com
20 mail2.example.com

The number at the start represents the priority. The lower the number, the more priority it gains. In the above case, the server tries mail1 when attempting to deliver an email. If it fails, then it tries mail2 to deliver an email.

Example MX Record

An example MX record for the domain example.com look like the following:

Type Domain Name Priority MX TTL
MX example.com 10 mail1.example.com 3600
MX example.com 20 mail2.example.com 3600

Here,

  • MX is the record type.
  • example.com is the domain of the record.
  • 10 & 20 are the priority of the record. The lower the value, the more priority it gets.
  • mail1.example.com & mail2.example.com are the values of the record.
  • 3600 is the TTL (time to live) of the record in seconds. TTL is the time that tells the DNS resolver how long cache the DNS query before requesting a new one.

Priority in DNS MX record

In the MX record, the value represents the priority. The lower the value, the more priority that the mail server will receive in delivering the mail. The MX record backup is another MX record for the domain with a higher priority value.

In the above case, the server tries mail1 when attempting to deliver an email. If it fails, then it tries mail2 to deliver an email.

However, to spread the load across many mail servers, a single mail server cannot manage it. The multiple MX records with the same priority value can process the email where one is picked randomly.

An example MX record with a combination of MX record backup and load balanced for the domain example.com look like the following:

Type Domain Name Priority MX TTL
MX example.com 10 mail1.example.com 3600
MX example.com 10 mail2.example.com 3600
MX example.com 20 mail3.example.com 3600

In this example, the mail servers mail1.example.com and mail2.example.com will get an equal chance to handle email processing. If both fail to respond, then the mail server at mail3.example.com will take processing the email.

Lookup MX Record

we can check our MX records via DIG or nslookp command as follows:

  • $ dig MX example-domain.com
  • $ nslookup -query=mx example-domain.com

Alternatively, we could use any available online tool, such as G Suite Toolbox DIG or MX Lookup Tool.

FAQ

Question: Do I need an “A” record for my mail server alongside with my domain’s MX records?

Answer: If the mail server is part of the same domain namespace (lies in the zone), then an “A” record is required.

Question: What is the purpose of using multiple MX records with various priorities?

Answer: This approach provides a backup MX record that can be used if the main MX (the one with the lowest priority) is not available.

Question: Can I add multiple MX records with the same priority for load balancing?

Answer: Yes, you can. Setting the priority levels equal to each other will make your MX records to act in Round-Robin mode.

Related: