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:dmarc-reports@yourdomain.com"
💡 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.









