Look up DMARC and DKIM records from the command line

· 3 min read

DMARC and DKIM are TXT records, but they do not sit on the domain itself. Each has a fixed name in front of it, and once you know that name the check takes seconds. Below are the commands for dig, nslookup, PowerShell and host, how to find the right DKIM selector, and what the usual failures look like.

Create a DMARC record

The command for DMARC and DKIM

DMARC is published at _dmarc.example.com, DKIM at selector._domainkey.example.com. Choose the record and your tool, fill in domain and selector, and copy the command.

What to check
Tool

Only inserted into the commands in your browser.

Only inserted into the commands in your browser.

DMARC · dig · Linux, macOS

DMARC always lives at _dmarc in front of the domain. The answer starts with v=DMARC1; the part that matters is p= (none, quarantine or reject).

Shell
dig +short TXT _dmarc.example.com
Sample output
"v=DMARC1;p=reject;sp=reject;adkim=s;aspf=s"

DMARC · nslookup · Windows, Linux, macOS

The same record with nslookup, on Windows as well as Linux and macOS. If nslookup reports NXDOMAIN, the domain has no DMARC record.

Shell
nslookup -type=TXT _dmarc.example.com
Sample output
Non-authoritative answer:
_dmarc.example.com	text = "v=DMARC1;p=reject;sp=reject;adkim=s;aspf=s"

DMARC · PowerShell · Windows

Prints only the record text. Without a record Resolve-DnsName raises an error instead of returning an empty answer.

PowerShell
Resolve-DnsName -Name _dmarc.example.com -Type TXT | Select-Object -ExpandProperty Strings

DMARC · host · Linux, macOS

The short form for Linux and macOS.

Shell
host -t TXT _dmarc.example.com
Sample output
_dmarc.example.com descriptive text "v=DMARC1;p=reject;sp=reject;adkim=s;aspf=s"

DKIM · dig · Linux, macOS

DKIM needs the selector. The answer carries the public key after p=; a host name on the line before it means the entry is a CNAME to your mail provider's key.

Shell
dig +short TXT selector1._domainkey.example.com
Sample output
"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA…"

DKIM · nslookup · Windows, Linux, macOS

nslookup shows long keys as several quoted chunks. That is correct; one chunk holds at most 255 characters.

Shell
nslookup -type=TXT selector1._domainkey.example.com
Sample output
Non-authoritative answer:
selector1._domainkey.example.com	text = "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA…"

DKIM · PowerShell · Windows

The parentheses print only the Strings property, that is the key. If the entry is a CNAME, Resolve-DnsName follows it on its own.

PowerShell
(Resolve-DnsName -Name selector1._domainkey.example.com -Type TXT).Strings

DKIM · host · Linux, macOS

The short form for Linux and macOS.

Shell
host -t TXT selector1._domainkey.example.com
Sample output
selector1._domainkey.example.com descriptive text "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA…"

The reserved domain example.com publishes both, by the way: DMARC with p=reject and a DKIM record with an empty p=. An empty key means "revoked", so any signature using that selector fails. That is how you lock down a domain that never sends mail.

Finding the DKIM selector

The selector is chosen freely and DNS offers no way to list it. The reliable source is a real message from the domain: in the DKIM-Signature header the selector follows s= and the signing domain follows d=.

HTTP
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.org;
	s=selector1; h=from:to:subject:date:message-id; bh=…; b=…

With no message at hand, try the provider defaults: Microsoft 365 uses selector1 and selector2, Google Workspace defaults to google, many bulk senders use s1 and s2 or k1. With Microsoft 365 and most sending services the entry is a CNAME; the lookup follows it and prints the target first, then the key.

What the DMARC record says

Tags are separated by semicolons. These are the ones you will meet:

  • p= is the policy for the domain: none (monitor only), quarantine (send to spam) or reject.
  • sp= applies to subdomains. Without it they inherit p=.
  • rua= is the address for daily aggregate reports. Without rua you never learn who sends in your name.
  • adkim= and aspf= decide whether domains must match exactly (s) or the organizational domain is enough (r, the default).
  • pct= applies the policy to only a share of messages, meant for a gradual rollout.

Errors you can read from the answer

Where the lookup goes wrong and what is behind it:

  • Empty answer for _dmarc.sub.example.com: not an error. Subdomains without their own record fall back to the main domain's DMARC record, so query _dmarc.example.com.
  • NXDOMAIN for _dmarc.example.com: there is no DMARC record. Receivers treat the domain like p=none without reports.
  • Two lines with v=DMARC1: two records are invalid and receivers ignore both.
  • The record does not start with v=DMARC1 or has quotes inside the value: a typo, or an editor that stored the quotes.
  • Empty answer for DKIM: wrong selector, or the DNS host created "selector1._domainkey.example.com.example.com" because the domain was entered twice.
  • DKIM returns a host name but no key: the CNAME points nowhere. With Microsoft 365 that is the case until DKIM is enabled in the Defender portal.
  • The key stops mid-value: the DNS host cut the entry at 255 characters. The key has to be split into several strings or published through a CNAME.

Checking without a terminal

The DMARC checker reads the record, validates the syntax and rates how well the policy protects against forged mail. The DKIM checker tries the common selectors on its own and reports key length and revoked keys, so you do not need to know the selector. The glossary explains how DKIM and DMARC work together.

Frequently asked questions

How do I look up a DMARC record with nslookup?
nslookup -type=TXT _dmarc.example.com. Mind the underscore, and that _dmarc goes in front of the domain, not after it.
How do I find the DKIM selector of a domain?
It follows s= in the DKIM-Signature header of a message sent from that domain. DNS alone cannot list it; you can only try known names such as selector1, google, s1 or k1.
Why does the DKIM lookup return a CNAME?
Many providers manage the key themselves and only have you point a CNAME at their entry. That lets them rotate the key without you touching DNS. The lookup follows the CNAME automatically.
Does a DMARC record cover subdomains?
Yes. A subdomain without its own record uses the organizational domain's record, with sp= if present and p= otherwise.
Check now

Free DMARC record check: policy (none, quarantine, reject), pct, reporting addresses and syntax errors. With recommendations for moving to p=reject.

DomainWarn monitors DMARC and DKIM for all client domains, analyses the DMARC reports and alerts you when a key disappears or a policy is weakened.

Monitor this domain continuously14-day free trial, no credit card.

More guides