Finding Your Email's Mail Server Using nslookup

Sometimes, you need to know the exact address of your email provider's mail server. This might be necessary to configure an email client like Outlook or troubleshoot email delivery problems. If the common patterns like mail.domainname.com or smtp.domainname.com don't work, here's how to find your mail server using the nslookup command:

Step-by-Step Guide

  1. Open a Command Prompt:

    • Windows: Press the Windows key, type "cmd", and press Enter.
    • macOS/Linux: Open the Terminal application.
  2. Start nslookup:

    • Type nslookup and press Enter. This will open the nslookup interactive mode.
  3. Check Your DNS Server:

    • You'll see your computer's default DNS server information displayed. This is usually provided by your ISP.
  4. Set Query Type to MX:

    • Type set type=mx and press Enter. This tells nslookup to look for MX (Mail eXchange) records, which specify the mail servers for a domain.
  5. Enter the Domain Name:

    • Type the domain name of the email address (e.g., gmail.com, yahoo.com, yourdomain.com) and press Enter.
  6. Review the Output:

    • nslookup will display the MX records for the domain. Each record will show:
      • Preference: A numerical value indicating the priority of the mail server. Lower numbers mean higher priority.
      • mail exchanger: The hostname of the mail server. This is what you're looking for!

Example

Bash
C:\Users\yourname> nslookup
Default Server:  dns.yourisp.com
Address:  192.168.1.1

> set type=mx
> gmail.com

Server:  dns.yourisp.com
Address:  192.168.1.1

Non-authoritative answer:
gmail.com      MX preference = 
5, mail exchanger = gmail-smtp-in.l.google.com gmail.com MX preference = 10, mail exchanger = alt1.gmail-smtp-in.l.google.com gmail.com MX preference = 20, mail exchanger = alt2.gmail-smtp-in.l.google.com gmail.com MX preference = 30, mail exchanger = alt3.gmail-smtp-in.l.google.com gmail.com MX preference = 40, mail exchanger = alt4.gmail-smtp-in.l.google.com

In this example, gmail-smtp-in.l.google.com is the primary mail server for gmail.com.

Tips and Troubleshooting

  • Multiple MX Records: Many domains have multiple MX records for redundancy. Email will be routed to the server with the lowest preference number first.

  • No MX Records: If no MX records are found, the domain might not have email service configured, or there might be a DNS issue.

  • Non-Authoritative Answers: If you get a "non-authoritative answer," the information might be outdated. Try clearing your DNS cache or using a public DNS server like Google's (8.8.8.8) or Cloudflare's (1.1.1.1).

  • Using a Specific DNS Server: You can specify a DNS server to query by adding its IP address after the domain name:

    Bash
    nslookup -query=mx gmail.com 8.8.8.8
    

Beyond nslookup

While nslookup is useful, consider these alternatives:

  • dig: A more advanced command-line tool with more detailed output.
  • Online Tools: Many websites provide user-friendly interfaces for DNS lookups, including MX record checks.