Skip to main content

How to Use Command-Line Tools for Diagnosing Email Security Issues (dig, nslookup, host)

Diagnose and troubleshoot email security issues using dig, nslookup, and host to ensure SPF, DKIM, and DMARC compliance.

Updated over a month ago

Email security is a critical concern for organizations and individuals alike. Attackers often exploit vulnerabilities in email protocols, leading to phishing, spoofing, and other cyber threats. To prevent such issues, administrators need to diagnose and analyze email-related DNS records, such as DMARC, SPF, DKIM, and MX records.

Several command-line tools are available for diagnosing email security issues, including:

  • dig (Domain Information Groper)

  • nslookup (Name Server Lookup)

  • host (Simple DNS lookup tool)

This guide will walk you through how to use these tools effectively to troubleshoot email security problems.


1. Understanding Email Security and DNS Records

Before diving into command-line tools, letโ€™s understand the key DNS records involved in email security:

๐Ÿ“Œ SPF (Sender Policy Framework)

  • Defines which mail servers are authorized to send emails on behalf of a domain.

  • Helps prevent email spoofing.

๐Ÿ“Œ DKIM (DomainKeys Identified Mail)

  • Uses cryptographic signatures to verify email authenticity.

  • Ensures emails are not altered during transit.

๐Ÿ“Œ DMARC (Domain-based Message Authentication, Reporting, and Conformance)

  • Protects against spoofing by enforcing SPF and DKIM policies.

  • Provides reporting mechanisms to monitor unauthorized email activity.

๐Ÿ“Œ MX (Mail Exchange) Records

  • Defines the mail servers responsible for receiving emails for a domain.

  • Ensures emails are routed correctly.


2. Using dig to Analyze Email Security Records

The dig command is a powerful tool for querying DNS records and troubleshooting email issues.

๐Ÿ”น Checking MX Records (Mail Server Configuration)

To check the mail servers configured for a domain:

bashCopyEditdig MX yourdomain.com +short

Example Output:

CopyEdit10 mail.yourdomain.com. 20 backupmail.yourdomain.com.

๐Ÿ’ก This means emails for yourdomain.com will be handled by mail.yourdomain.com (priority 10) and backupmail.yourdomain.com (priority 20).

๐Ÿ”น Verifying SPF Records

To check if SPF is correctly configured:

bashCopyEditdig TXT yourdomain.com +short

Example Output:

arduinoCopyEdit"v=spf1 include:_spf.google.com -all"

๐Ÿ’ก This means only Googleโ€™s mail servers are allowed to send emails on behalf of this domain.

๐Ÿ”น Checking DKIM R

ecords

To verify DKIM configuration:

bashCopyEditdig TXT selector._domainkey.yourdomain.com +short

๐Ÿ’ก Replace selector with the actual selector name (e.g., default).

๐Ÿ”น Checking DMARC Records

To ensure DMARC is properly set up:

bashCopyEditdig TXT _dmarc.yourdomain.com +short

Example Output:

perlCopyEdit"v=DMARC1; p=reject; rua=mailto:[email protected]"

๐Ÿ’ก This enforces a strict DMARC policy (reject) and sends reports to the specified email.


3. Using nslookup for Email Security Diagnosis

The nslookup command is another useful tool for querying DNS records.

๐Ÿ”น Checking MX Records

bashCopyEditnslookup -query=MX yourdomain.com

Example Output:

javaCopyEdityourdomain.com mail exchanger = 10 mail.yourdomain.com. yourdomain.com mail exchanger = 20 backupmail.yourdomain.com.

๐Ÿ’ก Confirms the mail server priority and setup.

๐Ÿ”น Checking SPF Records

bashCopyEditnslookup -type=TXT yourdomain.com

๐Ÿ’ก Verifies SPF configurations like v=spf1 include:_spf.google.com -all.

๐Ÿ”น Checking DKIM Records

bashCopyEditnslookup -type=TXT selector._domainkey.yourdomain.com

๐Ÿ’ก Ensures DKIM public key is correctly published.

๐Ÿ”น Checking DMARC Records

bashCopyEditnslookup -type=TXT _dmarc.yourdomain.com

๐Ÿ’ก Confirms DMARC policy and reporting address.


4. Using host for Quick DNS Checks

The host command is a simple alternative to dig and nslookup.

๐Ÿ”น Checking MX Records

bashCopyEdithost -t MX yourdomain.com

Example Output:

csharpCopyEdityourdomain.com mail is handled by 10 mail.yourdomain.com. yourdomain.com mail is handled by 20 backupmail.yourdomain.com.

๐Ÿ’ก Verifies mail server setup.

๐Ÿ”น Checking SPF Records

bashCopyEdithost -t TXT yourdomain.com

๐Ÿ’ก Displays SPF, DMARC, and DKIM records.

๐Ÿ”น Checking DMARC Records

bashCopyEdithost -t TXT _dmarc.yourdomain.com

๐Ÿ’ก Verifies DMARC configuration.


5. Common Email Security Issues & Solutions

Issue

Cause

Solution

Emails going to spam

Missing SPF/DKIM/DMARC

Verify SPF, DKIM, and DMARC records

Spoofed emails sent from your domain

Weak DMARC policy

Set DMARC to p=reject

Bounce-back errors

Incorrect MX records

Ensure MX records point to correct mail servers

Delayed email delivery

Misconfigured mail servers

Check MX record priorities


Conclusion

Using command-line tools like dig, nslookup, and host can help diagnose and troubleshoot email security issues effectively. Regularly monitoring SPF, DKIM, DMARC, and MX records ensures better email deliverability and protection against spoofing and phishing attacks.

If youโ€™re managing an email infrastructure, integrating these checks into your routine email security audits will help enhance security, compliance, and trust in email communications.

๐Ÿ’ก Need help with DMARC, SPF, or DKIM setup? YourDMARC provides advanced email security tools to simplify compliance and protect your brand.

Did this answer your question?