Securing Infrastructure Access at Scale in Large Enterprises
Dec 12
Virtual
Register Now
Teleport logoTry For Free

MX Lookup

Quickly lookup MX records to find mail server configurations for a domain.

Loading tool configuration...

MX (Mail Exchanger) records are a critical component of email delivery that confuse many users. In this primer, we'll demystify what MX records are, how they work behind the scenes to route your email, and how you can use them to troubleshoot email issues and improve your email security. We'll even explore how to integrate MX record management into your DevOps processes for maximum consistency and minimum headaches.

What is an MX Record?

At their core, MX records are simply DNS (Domain Name System) records that tell the world which servers accept email for your domain. When someone sends an email to [email protected], their email server looks up the MX records for example.com to know where to deliver the message.

How MX Records Work

Here's a simplified play-by-play of how MX records route an email from sender to recipient:

  1. Alice sends an email from [email protected] to [email protected]
  2. Alice's email server does a DNS lookup for the MX records of startup.com
  3. The DNS server replies with MX records pointing to mail.startup.com
  4. Alice's server opens an SMTP connection to mail.startup.com and delivers the email
  5. mail.startup.com puts the email in Bob's inbox

Easy peasy, right? Of course, there's a lot more going on under the hood - MX record priorities, fallback servers, spam checks galore - but that's the gist of it. MX records form the backbone that email runs on.

Anatomy of an MX Record

A typical MX record looks something like this:

startup.com.  3600  IN  MX  10 mail.startup.com.

Let's break that down:

  • startup.com.: The domain the MX record applies to (that trailing dot just means "this is the full domain name")
  • 3600: The TTL (time-to-live) in seconds, basically how long to cache the record
  • IN: Stands for "Internet", you'll almost always see this
  • MX: Indicates this is an MX record (vs A, CNAME, TXT, etc)
  • 10: The priority value. Lower values = higher priority.
  • mail.startup.com.: The hostname of the email server (again with the trailing dot)

If you see multiple MX records for a domain, email servers will try to deliver to the server with the lowest priority value first. If that fails, they'll fall back to the next lowest, and so on. This adds redundancy in case a primary server goes belly up.

Troubleshooting Email with MX Records

Alright, storytime. Let's say you're the resident email admin at startup.com. Your users are complaining that emails from bigcorp.com never seem to arrive. You check your spam filters - nada. Firewall log - zilch. What's the deal?

Believe it or not, a simple MX lookup can often reveal the culprit behind missing emails. Here are some troubleshooting tips to try:

1. Check that MX records exist

First things first: make sure your domain actually has MX records! You can use the trusty dig command for this:

dig startup.com MX

You should get an answer like this:

; <<>> DiG 9.10.6 <<>> startup.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60863
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;startup.com.			IN	MX

;; ANSWER SECTION:
startup.com.		300	IN	MX	20 in2-smtp.messagingengine.com.
startup.com.		300	IN	MX	10 in1-smtp.messagingengine.com.

If you don't see any MX records in the output, there's your problem. No MX means no email delivery. You'll need to add MX records pointing to your email servers.

If you do see MX records, make sure they're pointing to the right place. If your email is hosted on mail.startup.com but your MX points to old-server.startup.com, that explains why emails are getting lost.

2. Verify server responsiveness

Even if your MX records look good, the server itself might be having issues. You can test the connection with telnet like this:

telnet mail.startup.com 25

If the connection fails, your email server might be down or misconfigured. Time to break out the server logs and start digging.

Quick heads up though - lots of email servers these days block these connections for security reasons. If it fails, your server might still be fine! Try checking your server logs or reaching out to your email provider for the right way to test.

3. Check priority and order

Remember how I mentioned MX record priorities earlier? They can trip you up if you're not careful. Make sure your primary server has the LOWEST priority value, usually 10.

If your backup server has a lower value than your main one, guess what? Email will flow to your backup first, bypassing the primary altogether! Not ideal.

4. Look for malformed records

One stray character in your MX records can completely break email. Here are some malformed records I've seen in the wild:

  • 10 mail.startup.com - That trailing dot will mess you up! Should be: 10 mail.startup.com.
  • 10 mail.startup.com.com - Doesn't match the actual hostname.
  • 10 263.43.24.122 - MX should point to a hostname, not IP. Use an A record for that.

The lesson: triple check your records for typos and syntax errors. Your email depends on it!

Securing Your MX Records

Now that we've covered the email routing side, let's talk security. Misconfigured MX records are a common vector for phishing attacks and email spoofing. Here's how to fortify your email defenses:

1. Lock down your MX

Make sure your MX records ONLY point to email servers you control and trust. If an attacker adds their server as an MX record for your domain, they can intercept emails intended for you! Yikes.

For an extra layer of security, consider using DNSSEC (DNS Security Extensions) to digitally sign your MX records. This prevents attackers from tampering with your DNS and redirecting email on the sly.

2. Harden your SPF

MX records tell the world which servers handle email for your domain. SPF (Sender Policy Framework) flips the script, specifying which servers are allowed to send email on behalf of your domain. Make sure these lists line up!

A strong SPF policy is one of your best defenses against spammers and phishers who try to impersonate your domain. Start with ~all (softfail for unlisted servers) so you can test your setup without breaking anything, then tighten it up to -all (hardfail) once you’re confident everything is locked down.

3. Implement DKIM signing

Just like SPF validates the server, DKIM (DomainKeys Identified Mail) validates the email content hasn't been tampered with. It works by adding a digital signature to the message header that recipients can check for authenticity.

When combined with SPF, DKIM makes it really tough for attackers to spoof emails from your domain. It’s not a magic bullet, but it’s definitely a solid, heavy-duty round in your security arsenal.

Managing MX Records at Scale

If you're a fellow DevOps enthusiast like me, you're probably thinking "this manual MX stuff doesn't scale!" And you're absolutely right! Fiddling with MX records by hand is error-prone and unmanageable beyond a few domains.

The solution: infrastructure as code. By defining your MX records (and associated A, TXT, DKIM, etc records) in a structured format like JSON or YAML, you can automate your DNS with tools like Terraform and Ansible.

Imagine: your MX records living as versionable code, marching through your CI/CD pipeline, with automated tests making sure you didn't accidentally reroute your CEO's email to [email protected]. Automated alerts when MX configs drift out of sync, errant mail servers being declared persona non grata. Delightful!

I won't go into all the nitty gritty details here - that's a whole article in itself! But trust me, if you're managing email infra at scale, you need to hop on the infrastructure-as-code train ASAP. Your email team will thank you.

Wrapping Up

In this article, we've covered a lot of ground—from understanding how MX records route email, to troubleshooting delivery issues, securing your email infrastructure, and managing MX records at scale.

Here are the key takeaways:

  • MX records determine which servers handle email for your domain.
  • Misconfigurations in MX, A, and PTR records are common culprits behind email delivery issues.
  • Properly configuring SPF, DKIM, and DMARC alongside MX is crucial for strong email security.
  • Managing MX records as code is critical for maintaining reliable email infra at scale.

Hopefully you should now feel ready to tackle your MX record challenges—whether you're troubleshooting a single missing email or locking down an enterprise-grade system.

And now, if you'll excuse me, I’ve got some MX records to automate...

Background image

Try Teleport today

In the cloud, self-hosted, or open source
Get StartedView developer docs