schedule 12-min read

Adding a DMARC Record in Azure DNS: Portal, CLI and PowerShell

DMARC AI editorial team · Last updated

Add an Azure DNS DMARC record at _dmarc via the portal, Azure CLI or PowerShell, plus Microsoft 365 SPF and DKIM CNAMEs, for MSPs managing many tenants.

01

Introduction

To add a DMARC record in Azure DNS, create a TXT record set named _dmarc in the client's public DNS zone, with a value such as v=DMARC1; p=none; rua=mailto:reports@example.net. You can do it in the Azure portal, with the Azure CLI or with Azure PowerShell. Azure appends the zone name for you.

This guide covers all three methods, the SPF and DKIM records a Microsoft 365 domain needs in the same zone, and the habits that keep changes safe when an MSP manages DNS zones across many client subscriptions. For the protocol itself, start with the DMARC guide. If the zone is hosted on Cloudflare instead, see how to add a DMARC record in Cloudflare DNS.

02

Key takeaways

  • The DMARC record is a TXT record set with the relative name _dmarc. Never type the full name; Azure adds the zone.
  • In the CLI, add-record adds a second record to an existing set. Two DMARC records at one name are both discarded, so replace the value instead of adding.
  • Microsoft 365 needs an SPF TXT record at @ and two DKIM CNAMEs (selector1._domainkey, selector2._domainkey) alongside DMARC.
  • Microsoft's own DMARC guidance still shows a percentage tag. RFC 9989 removed it, so leave it out.
  • For portfolios, combine Azure Lighthouse or per-client access with the DNS Zone Contributor role, and check for resource locks before changing records.
03

Which records does a Microsoft 365 domain need in Azure DNS?

A Microsoft 365 custom domain needs three email authentication records in its Azure DNS zone: an SPF TXT record at the apex, two DKIM CNAME records and a DMARC TXT record. Azure DNS uses relative names, so you enter only the part before the zone name.

Purpose Type Name in Azure DNS Value (example for contoso.com)
SPF TXT @ v=spf1 include:spf.protection.outlook.com -all
DKIM selector 1 CNAME selector1._domainkey Value from the Defender portal or Get-DkimSigningConfig
DKIM selector 2 CNAME selector2._domainkey Value from the Defender portal or Get-DkimSigningConfig
DMARC TXT _dmarc v=DMARC1; p=none; rua=mailto:reports@example.net

Microsoft confirms that SPF and DMARC records are created at the DNS host, not in Microsoft 365, in its guides to setting up SPF and setting up DMARC. The one exception is the *.onmicrosoft.com domain, whose DMARC record is added in the Microsoft 365 admin center under Settings > Domains, not in Azure DNS.

04

Is the Azure DNS zone actually authoritative?

Check delegation first. An Azure DNS zone only answers on the internet once the registrar's name servers point to the Azure DNS name servers listed on the zone's overview page (names like ns1-37.azure-dns.com). A zone that exists in Azure but is not delegated accepts your records and serves them to nobody.

$ dig +short NS contoso.com
ns1-37.azure-dns.com.
ns2-37.azure-dns.net.
ns3-37.azure-dns.org.
ns4-37.azure-dns.info.

If the answer shows another provider, the live zone is elsewhere. This is common in inherited client estates, where a test zone was created in Azure years ago and never delegated. When the name servers belong to a shared web host, follow how to add a DMARC record in cPanel instead. If they are Route 53 name servers, with names like ns-123.awsdns-45.com, follow how to add a DMARC record in Amazon Route 53. Our DNS lookup tool shows the same answer without a command line.

05

How do you add a DMARC record in the Azure portal?

Open the DNS zone, go to Record sets, select + Add, enter _dmarc as the name, choose TXT as the type, set a TTL and paste the DMARC value. Select Add to save. The steps follow Microsoft's Azure DNS portal quickstart:

  1. In the Azure portal, open the client's public DNS zone, for example contoso.com.
  2. Select Record sets, then + Add. The Add a record set window opens.
  3. Name: _dmarc (relative; do not type _dmarc.contoso.com, because Azure appends the zone name).
  4. Type: TXT.
  5. TTL: 1, with TTL unit set to Hours, is a sensible starting value.
  6. Value: the full DMARC string on one line.
  7. Select Add.

A first record for a client in monitoring mode looks like this:

v=DMARC1; p=none; rua=mailto:dmarc-reports@example.net

If you are unsure of the syntax, the DMARC record generator builds a valid value, and how to create a DMARC record explains each tag.

06

How do you add a DMARC record with the Azure CLI?

Use az network dns record-set txt add-record with the resource group, the zone and the relative name _dmarc. Quote the whole value, because the semicolons would otherwise end the shell command. If the record set does not exist yet, Azure creates it with a default TTL of 3600 seconds.

az network dns record-set txt add-record 
  --resource-group rg-dns-contoso 
  --zone-name contoso.com 
  --record-set-name _dmarc 
  --value "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.net"

Check the result:

az network dns record-set txt show 
  --resource-group rg-dns-contoso 
  --zone-name contoso.com 
  --name _dmarc

The commands are documented in Manage DNS records in Azure DNS using the Azure CLI and the az network dns record-set txt reference.

How do you change the DMARC policy with the CLI without breaking it?

Remove the old value, then add the new one. Running add-record again with a new policy does not replace anything: it adds a second TXT record to the _dmarc set. Under RFC 9989, Section 4.10, if multiple DMARC records are returned for one name, they are all discarded, so the domain effectively has no policy.

az network dns record-set txt remove-record 
  -g rg-dns-contoso -z contoso.com -n _dmarc 
  --keep-empty-record-set 
  -v "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.net"

az network dns record-set txt add-record 
  -g rg-dns-contoso -z contoso.com -n _dmarc 
  -v "v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.net"

--keep-empty-record-set keeps the set (and its TTL and any record-set permissions) while it is briefly empty. The value passed to remove-record must match the existing record exactly, so copy it from the show output.

07

How do you add a DMARC record with Azure PowerShell?

Create the record set with New-AzDnsRecordSet and a record built by New-AzDnsRecordConfig -Value. This creates the _dmarc TXT set and its single record in one step, as shown in Manage DNS records in Azure DNS using Azure PowerShell.

New-AzDnsRecordSet -Name "_dmarc" -RecordType TXT `
  -ZoneName "contoso.com" -ResourceGroupName "rg-dns-contoso" -Ttl 3600 `
  -DnsRecords (New-AzDnsRecordConfig -Value "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.net")

To change the policy later, edit the existing set rather than creating a new one:

$rs = Get-AzDnsRecordSet -Name "_dmarc" -RecordType TXT `
  -ZoneName "contoso.com" -ResourceGroupName "rg-dns-contoso"
Remove-AzDnsRecordConfig -RecordSet $rs -Value "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.net"
Add-AzDnsRecordConfig -RecordSet $rs -Value "v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.net"
Set-AzDnsRecordSet -RecordSet $rs

Nothing changes in DNS until Set-AzDnsRecordSet runs, so both edits land together. Azure PowerShell uses Etags by default, so the commit fails if someone else changed the set in the meantime. Treat that failure as a signal to re-read the record, not as a reason to add -Overwrite.

08

How do you add the Microsoft 365 SPF and DKIM records in Azure DNS?

Add SPF as a TXT record in the apex (@) record set and add each DKIM selector as a CNAME record set. Take the DKIM targets from Microsoft 365, never from a template, because the target format depends on the tenant and on when the domain was added.

SPF at the apex

In Azure DNS, all TXT records at @ live in one record set. It often already holds domain verification strings such as MS=ms12345678. Add the SPF record to that set instead of replacing it, and make sure the set contains only one v=spf1 record, since multiple SPF records cause a permerror. If a second sender is involved, merge it into the existing record as described in multiple SPF records: how to merge them.

az network dns record-set txt add-record 
  -g rg-dns-contoso -z contoso.com -n "@" 
  -v "v=spf1 include:spf.protection.outlook.com -all"

Microsoft lists different include: values for GCC High and DoD (spf.protection.office365.us) and for Microsoft 365 operated by 21Vianet (spf.protection.partner.outlook.cn).

DKIM CNAMEs

Get the two CNAME targets from the Defender portal (Email & collaboration > Policies & rules > Threat policies > Email authentication settings > DKIM) or from Exchange Online PowerShell:

Get-DkimSigningConfig -Identity contoso.com | Format-List Name,Enabled,Status,Selector1CNAME,Selector2CNAME

Then create one CNAME record set per selector. A CNAME set holds exactly one record, so set-record creates or replaces it:

az network dns record-set cname set-record 
  -g rg-dns-contoso -z contoso.com -n selector1._domainkey 
  --cname "selector1-contoso-com._domainkey.contoso.n-v1.dkim.mail.microsoft"

Microsoft's DKIM configuration guide explains that custom domains added since May 2025 use targets ending in dkim.mail.microsoft, while older domains keep the onmicrosoft.com format. The example target above is illustrative only. Once both CNAMEs resolve, enable signing in the Defender portal or with Set-DkimSigningConfig -Identity contoso.com -Enabled $true. DMARC for Microsoft 365 clients covers the full sequence.

09

Should the Azure DNS DMARC record include pct?

No. Microsoft's DMARC setup article still shows the percentage tag and a sampling ramp, but RFC 9989 replaced RFC 7489 (now obsoleted) and removed the pct tag. Receivers following the current standard ignore it. Publish policies whole: p=none, then p=quarantine, then p=reject, moving up only when aggregate reports show every legitimate sender passing with alignment.

If you want a cautious step, RFC 9989 defines t=y, which asks receivers to apply the policy one level lower than published:

v=DMARC1; p=quarantine; t=y; rua=mailto:dmarc-reports@example.net

Remove t=y once the level is confirmed. DMARCbis for Microsoft 365 clients explains what else changed. The UK NCSC email security and anti-spoofing guidance follows the same principle: start at p=none, use reports to fix legitimate senders, then move to enforcement.

10

How should MSPs manage DMARC records across many Azure tenants?

Treat Azure DNS as one more DNS host in the portfolio, with consistent access, naming and change control. The main decisions are how your team reaches each client's zones, which role it holds there and how changes are recorded.

  • Access. With Azure Lighthouse, a client delegates its subscription to your tenant, and your engineers can run Azure CLI and PowerShell against it. Lighthouse supports built-in roles except Owner, which suits least privilege.
  • Role. The built-in DNS Zone Contributor role manages public DNS zones and nothing else. Azure also supports permissions on a single record set, useful when a client's own team must keep control of other records. See protecting DNS zones and records.
  • Locks. A ReadOnly lock on a zone blocks all record changes, so check for locks before a scheduled policy move. A CanNotDelete lock on a record set does not stop someone emptying it.
  • Inventory. In each subscription, az network dns zone list --query "[].{zone:name, rg:resourceGroup}" -o table lists the zones, which helps you confirm no client domain lives in Azure without a _dmarc record set.
  • Change records. Log every DMARC edit with the old value, the new value and the reason, so a rollback is a single command. DMARC change management for MSP portfolios suggests a format.

If aggregate reports go to a mailbox on a different domain than the client's, the receiving domain must publish an authorisation record (contoso.com._report._dmarc.example.net, value v=DMARC1), as defined in RFC 9990, Section 4. That record lives in the report receiver's zone, not the client's.

In DMARC AI, aggregate reports for every client domain arrive in one multi-tenant view, and the AI assistant can check the live _dmarc record after an Azure change to confirm the published policy matches what you intended.

11

How do you check the record after publishing?

Query _dmarc with dig or a DMARC checker and confirm that exactly one DMARC record comes back with the value you intended. Check again after the TTL has passed, because public resolvers may still serve the old answer:

$ dig +short TXT _dmarc.contoso.com
"v=DMARC1; p=none; rua=mailto:dmarc-reports@example.net"

To skip resolver caching, query one of the zone's Azure name servers with dig @ns1-37.azure-dns.com TXT _dmarc.contoso.com. The DMARC checker validates syntax and flags duplicate records.

12

FAQ

What name do I enter for a DMARC record in Azure DNS?

Enter _dmarc only. Azure DNS uses relative names and appends the zone, so _dmarc in the contoso.com zone becomes _dmarc.contoso.com. For a subdomain policy in the same zone, use _dmarc.marketing, which resolves to _dmarc.marketing.contoso.com.

Why does my domain show two DMARC records after an Azure CLI change?

Because az network dns record-set txt add-record adds a record to the existing set rather than replacing it. Receivers discard all DMARC records when more than one is returned. Remove the old value with remove-record, keeping the set, and confirm a single answer with dig.

Do I need to split a long DMARC record into 255-character strings in Azure?

No. Microsoft states that in the Azure portal, PowerShell and CLI you enter a single string per TXT record, and Azure divides it into 255-character segments automatically. Receivers join the segments back together. DMARC records are rarely long enough for this to matter.

Can I add the onmicrosoft.com DMARC record in Azure DNS?

No. The *.onmicrosoft.com domain is hosted by Microsoft, so you cannot add records for it in your own Azure DNS zone. Microsoft documents adding its _dmarc TXT record in the Microsoft 365 admin center under Settings, Domains, DNS records.

13

Final thoughts

Adding a DMARC record in Azure DNS takes a minute in any of the three interfaces. The mistakes that cause trouble are operational: a zone that is not delegated, a second record added by a CLI command, a percentage tag copied from old guidance, an apex TXT set overwritten along with its verification strings. Script the change, read the record back, and let the aggregate reports tell you when each client is ready for the next policy level.

Related articles

Related tools

Ready to Implement?

Get authenticated mail moving in minutes: start free, book a guided demo, or talk to the team about your stack.