Microsoft 365 Custom Domains & DNS Records (MX, TXT, CNAME, SRV)
Category: Microsoft 365 Administration › Domains › DNS Audience: M365 administrators, messaging/identity engineers, service desk (L2/L3) Applies to: Microsoft 365, Exchange Online, Microsoft Entra ID, Intune, Teams, Azure DNS (or any DNS host)
1. Purpose
- Explain every DNS record Microsoft 365 uses for a custom domain and what each one does.
- Show where to find expected values, the exact clicks, and what to enter at the DNS host.
- Show how to confirm what is live in public DNS for each record type.
- Give an answer pack for partner requests (eFax, banks, vendors) asking for MX / MTA / TLS details.
- Provide a PowerShell script that reports expected vs live for all record types across every domain in the tenant.
2. Key Terms
| Term | Full form | Meaning |
|---|
| DNS zone | – | All records for one domain, hosted at a DNS provider (Azure DNS, Cloudflare, GoDaddy…) |
| MX | Mail Exchanger | Which server receives email for the domain |
| TXT | Text | Free-text record – used for SPF, DMARC and domain verification |
| CNAME | Canonical Name | Alias from one name to another (Autodiscover, DKIM, Intune) |
| SRV | Service locator | Points a service + protocol + port to a host (legacy Skype/Teams federation) |
| A / AAAA | Address | Hostname → IPv4 / IPv6 |
| SPF | Sender Policy Framework | TXT listing servers allowed to send as the domain |
| DKIM | DomainKeys Identified Mail | Cryptographic signature on outgoing mail (published as CNAMEs) |
| DMARC | Domain-based Message Authentication, Reporting & Conformance | Policy telling receivers what to do when SPF/DKIM fail |
| MTA | Mail Transfer Agent | Mail server that accepts/relays email (M365 = Exchange Online Protection) |
| EOP | Exchange Online Protection | Microsoft's inbound mail gateway |
| TTL | Time To Live | Cache time in seconds (3600 = 1 hour) |
| Priority / Preference | – | Lower number = higher priority (0 is highest) |
| @ | – | Shorthand for the root (apex) of the domain, e.g. contoso.com |
3. Record Map – What Each Record Is For
| Service | Record | Host / Name | Without it… |
|---|
| Domain ownership | TXT | @ → MS=msXXXXXXXX | Domain can't be verified/added to the tenant |
| Inbound email | MX | @ | Mail never reaches Exchange Online |
| Outbound email trust | TXT (SPF) | @ | Mail marked as spam / spoofable |
| Outbound email signing | CNAME (DKIM) ×2 | selector1._domainkey, selector2._domainkey | No DKIM – weaker deliverability, DMARC relies on SPF only |
| Email policy | TXT (DMARC) | _dmarc | No spoofing enforcement or reporting |
| Outlook setup | CNAME | autodiscover | Users must configure Outlook manually |
| Device registration | CNAME | enterpriseregistration | Users must type server address for Entra device registration |
| Intune enrollment | CNAME | enterpriseenrollment | Users must type server address during MDM enrollment |
| Legacy Skype / Teams federation | CNAME ×2, SRV ×2 | sip, lyncdiscover, _sip._tls, _sipfederationtls._tcp | Only needed if the admin center lists them for your setup |
4. Standard Record Values
4.1 Email (Exchange Online)
| Type | Name / Host | Value / Target | Priority | TTL |
|---|
| MX | @ | <domain-key>.mail.protection.outlook.com (e.g. contoso-com.mail.protection.outlook.com) | 0 | 3600 |
| TXT (SPF) | @ | v=spf1 include:spf.protection.outlook.com -all | – | 3600 |
| CNAME | autodiscover | autodiscover.outlook.com | – | 3600 |
| CNAME (DKIM) | selector1._domainkey | Copy from Defender portal / admin center | – | 3600 |
| CNAME (DKIM) | selector2._domainkey | Copy from Defender portal / admin center | – | 3600 |
| TXT (DMARC) | _dmarc | v=DMARC1; p=none; rua=mailto:dmarc-reports@contoso.com (start) → p=quarantine → p=reject | – | 3600 |
Rules to remember
- MX: copy from the admin center; Exchange Online supports MX TTL under 6 hours only. Newer DNSSEC/DANE domains may show a
*.mx.microsoft host – still EOP. - SPF: only one SPF TXT per domain. If another service also sends mail, merge the includes into the single record (e.g.
v=spf1 include:spf.protection.outlook.com include:_spf.partner.example -all). - SPF lookups: maximum 10 DNS lookups per SPF evaluation – too many
include: entries break SPF. - DKIM: CNAMEs only work after you enable DKIM signing for the domain (section 7).
- DMARC: roll out gradually –
p=none (monitor) → p=quarantine → p=reject.
4.2 Identity & Device Management
| Type | Name / Host | Value / Target | TTL |
|---|
| TXT (verification) | @ | MS=msXXXXXXXX (unique per tenant – copy from admin center) | 3600 |
| CNAME | enterpriseregistration | enterpriseregistration.windows.net | 3600 |
| CNAME | enterpriseenrollment | enterpriseenrollment-s.manage.microsoft.com | 3600 |
- Keep the verification TXT after verification – it does no harm and helps if the domain is ever re-validated.
4.3 Legacy Skype for Business / Teams Federation (only if listed in the admin center)
| Type | Name / Host | Value / Target | Port | Priority | Weight |
|---|
| CNAME | sip | sipdir.online.lync.com | – | – | – |
| CNAME | lyncdiscover | webdir.online.lync.com | – | – | – |
| SRV | _sip._tls | sipdir.online.lync.com | 443 | 100 | 1 |
| SRV | _sipfederationtls._tcp | sipfed.online.lync.com | 5061 | 100 | 1 |
5. Where to Find Expected Records (Microsoft 365 Admin Center)
Role needed to view: Global Reader, Domain Name Administrator or Global Administrator.
| Step | Where to go / what to click | What you'll see |
|---|
| 1 | Open https://admin.cloud.microsoft and sign in | Admin center home |
| 2 | Left menu → … Show all → Settings → Domains (direct: https://admin.cloud.microsoft/#/Domains) | Every domain with Status (Healthy / Incomplete setup / Possible service issues) |
| 3 | Click the domain name (e.g. contoso.com) | Tabs: Overview, DNS records, Users, Teams & groups, Apps |
| 4 | Click DNS records | Records grouped by service: Microsoft Exchange, Basic Mobility and Security / Intune, Skype for Business |
| 5 | Click a record's radio button | Side panel with Type, Name, Value/Points to, Priority, TTL – use the copy icons |
| 6 | Optional: Download CSV file, Download zone file, Print (above the list) | Export for change records / DNS team hand-off |
| 7 | Optional: Manage DNS → More options → Add your own DNS → Continue | Wizard listing records to add, incl. Advanced options (DKIM, Intune) |
Reading the page
- Banner "To manage DNS records for … go to your DNS hosting provider: Azure" → tells you where to edit.
- Banner "Some of your DNS records aren't set up correctly" → at least one live record differs; check section 6.
- "Federated domain" in the header = sign-in federated to an external IdP. It does not affect MX/TXT/CNAME values.
- Ignore system domains (
*.onmicrosoft.com, *.mail.onmicrosoft.com, *.pstn.for-teams.com).
6. Confirm Live Records (Public DNS)
6.1 Commands per record type (PowerShell)
| Record | Command | Field to read |
|---|
| MX | Resolve-DnsName contoso.com -Type MX -Server 8.8.8.8 | NameExchange, Preference |
| SPF / verification TXT | Resolve-DnsName contoso.com -Type TXT -Server 8.8.8.8 | Strings (look for v=spf1 and MS=ms) |
| DMARC | Resolve-DnsName _dmarc.contoso.com -Type TXT -Server 8.8.8.8 | Strings (starts v=DMARC1) |
| Autodiscover | Resolve-DnsName autodiscover.contoso.com -Type CNAME -Server 8.8.8.8 | NameHost |
| DKIM | Resolve-DnsName selector1._domainkey.contoso.com -Type CNAME -Server 8.8.8.8 | NameHost |
| Intune | Resolve-DnsName enterpriseenrollment.contoso.com -Type CNAME -Server 8.8.8.8 | NameHost |
| SRV | Resolve-DnsName _sipfederationtls._tcp.contoso.com -Type SRV -Server 8.8.8.8 | NameTarget, Port, Priority, Weight |
-Server 8.8.8.8 queries a public resolver – avoids internal split-brain DNS answers.nslookup -type=<TYPE> <name> works the same in Command Prompt.
6.2 Azure DNS (if the zone is in Azure)
| Step | Where / click | What you'll see |
|---|
| 1 | https://portal.azure.com → search DNS zones | List of zones |
| 2 | Click the zone (e.g. contoso.com) | Overview with name servers |
| 3 | Left menu → DNS Management → Recordsets | All records – filter by Type (MX, TXT, CNAME, SRV) |
| 4 | Click a record set | Name, Type, TTL, Value(s) – edit only via approved change |
6.3 Web tools
| Tool | Where / button | Use for |
|---|
| MXToolbox | https://mxtoolbox.com → MX Lookup / SPF Record Lookup / DMARC Lookup / DKIM Lookup | Quick external validation and syntax checks |
| MXToolbox SMTP Test | https://mxtoolbox.com → SMTP Test | TLS / STARTTLS on the MX host |
7. Enable DKIM (Microsoft Defender Portal)
| Step | Where / click | What to enter |
|---|
| 1 | https://security.microsoft.com → Email & collaboration → Policies & rules → Threat policies | – |
| 2 | Email authentication settings → DKIM tab | List of domains with DKIM status |
| 3 | Click the domain | Flyout shows the two CNAME values |
| 4 | Publish both CNAMEs at the DNS host (section 4.1) | Host selector1._domainkey / selector2._domainkey |
| 5 | Wait for DNS propagation, then toggle Sign messages for this domain with DKIM signatures to Enabled | – |
Direct link: https://security.microsoft.com/authentication?viewid=DKIM
8. Answer Pack – Partner TLS Email Requests (eFax, Banks, Vendors)
| Form field | Select / enter | Why |
|---|
| Domain Name | contoso.com (one row per domain) | Each accepted domain is separate |
| Delivery Point | ☑ MX Record | Preferred – Microsoft IPs rotate |
| A Record / IP Address | Leave blank | Not used with MX |
| Specific MTA | contoso-com.mail.protection.outlook.com | EOP hostname from the MX |
| Certificate Authority | ☑ Third-Party | EOP uses a public-CA certificate (subject mail.protection.outlook.com) |
Reply template
TLS details for our email domains:
• contoso.com – Delivery: MX Record – MTA: contoso-com.mail.protection.outlook.com – CA: Third-Party
• fabrikam.com – Delivery: MX Record – MTA: fabrikam-com.mail.protection.outlook.com – CA: Third-Party
Hosted on Microsoft Exchange Online (public-CA certificates).
Please do not use IP addresses – Microsoft rotates them.
Checklist before sending
Optional – force TLS: https://admin.exchange.microsoft.com → Mail flow → Connectors → + Add a connector → Partner organization → Office 365 → ☑ Reject email messages if they aren't sent over TLS. Validate before enabling – a wrong connector rejects mail.
9. Best Practices & Ideas
| # | Recommendation | Benefit |
|---|
| 1 | Run the script below monthly (Azure Automation / scheduled task) and alert on any Mismatch / Missing | Catches accidental DNS edits before users notice |
| 2 | One SPF per domain, under 10 lookups, ending in -all | Reliable SPF pass |
| 3 | Enable DKIM for every sending domain | Stronger authentication, DMARC alignment |
| 4 | Roll DMARC from p=none → quarantine → reject while reviewing rua reports | Blocks spoofing without breaking legitimate mail |
| 5 | Park unused domains: v=spf1 -all, DMARC p=reject, null MX (0 .) | Stops attackers abusing idle domains |
| 6 | Hand partners hostnames, never IPs | No breakage when Microsoft rotates IPs |
| 7 | Drop TTL to 300 a day before a planned change, restore to 3600 after | Fast cut-over and rollback |
| 8 | Remove legacy Skype SRV/CNAMEs only after confirming the admin center no longer lists them | Clean zone without breaking federation |
| 9 | Keep a domain fact sheet (domain, DNS host, MX, DKIM status, DMARC policy, owner) | Answer audits / partner forms in minutes |
| 10 | Use Global Reader for reporting; restrict DNS write access | Least privilege |
| 11 | Record every DNS change in change management with before/after exports (zone file) | Audit trail and quick rollback |
| 12 | Consider SMTP DANE with DNSSEC for Exchange Online inbound where supported | Protects TLS against downgrade attacks |
10. Quick Reference
| Need | Go to |
|---|
| Expected records | https://admin.cloud.microsoft/#/Domains → domain → DNS records |
| Edit Azure-hosted zone | https://portal.azure.com → DNS zones → zone → Recordsets |
| DKIM | https://security.microsoft.com/authentication?viewid=DKIM |
| TLS connectors | https://admin.exchange.microsoft.com → Mail flow → Connectors |
| Live check | Resolve-DnsName <name> -Type <MX/TXT/CNAME/SRV> -Server 8.8.8.8 |
11. References (Microsoft Learn)
12. Script – Tenant DNS Health Report (MX, TXT, CNAME, SRV + DKIM & DMARC)
What it does
- Connects to Microsoft Graph with read-only scope
Domain.Read.All. - Lists verified custom domains (skips
onmicrosoft.com and Teams PSTN domains). - Reads every expected record Microsoft 365 requires (MX, TXT, CNAME, SRV) per domain.
- Resolves the live value from public DNS for each record.
- Adds extra checks Graph doesn't list: DMARC, DKIM selectors, multiple SPF records, SPF lookup count.
- Flags each row Match / Mismatch / Missing / Info.
- Exports a CSV and prints a summary of issues.
Prerequisites
- Windows PowerShell 5.1 or PowerShell 7 on Windows (
Resolve-DnsName). Install-Module Microsoft.Graph.Identity.DirectoryManagement -Scope CurrentUser- Global Reader (or higher).
# =====================================================================
# Script : Get-M365DomainDnsHealthReport.ps1
# Purpose: Compare expected (Microsoft 365) vs live (public DNS) records
# for every verified custom domain - MX, TXT, CNAME, SRV - plus
# extra DKIM, DMARC and SPF hygiene checks.
# Notes : No param() block - edit the variables below and run the
# script top-to-bottom or line by line.
# =====================================================================
# ----------------------------- Variables -----------------------------
$PublicDnsServer = "8.8.8.8" # Public resolver (avoids internal/split DNS)
$ExportFolder = "$env:USERPROFILE\Documents\DomainDnsReport" # CSV output folder
$IncludeOptional = $true # $true = also check records Microsoft marks optional
$CheckDkim = $true # $true = check selector1/selector2 DKIM CNAMEs
$CheckDmarc = $true # $true = check _dmarc TXT
$SpfLookupLimit = 10 # RFC limit for DNS lookups in SPF
$ExcludePatterns = @( # System domains to skip
"*.onmicrosoft.com",
"*.pstn.for-teams.com"
)
# --------------------------- Prerequisites ---------------------------
# Load the Graph module that contains the domain cmdlets
Import-Module Microsoft.Graph.Identity.DirectoryManagement -ErrorAction Stop
# Sign in with a read-only scope (interactive prompt)
Connect-MgGraph -Scopes "Domain.Read.All" -NoWelcome
# Create the export folder if needed
if (-not (Test-Path $ExportFolder)) {
New-Item -Path $ExportFolder -ItemType Directory | Out-Null
}
# Collection that every check adds rows to
$report = New-Object System.Collections.Generic.List[object]
# --------------------------- Helper blocks ---------------------------
# Resolve a DNS name safely and return only records of the requested type
# Usage: & $resolveLive <name> <type> ($args[0] = name, $args[1] = type)
$resolveLive = {
$lookupName = $args[0]
$lookupType = $args[1]
try {
Resolve-DnsName -Name $lookupName -Type $lookupType -Server $PublicDnsServer -DnsOnly -ErrorAction Stop |
Where-Object { $_.Type -eq $lookupType }
} catch {
@()
}
}
# Add one result row to the report
# Usage: & $addRow <domain> <service> <type> <name> <expected> <live> <status> <optional>
$addRow = {
$report.Add([PSCustomObject]@{
Domain = $args[0]
Service = $args[1]
Type = $args[2]
Name = $args[3]
Expected = $args[4]
Live = $args[5]
Status = $args[6]
Optional = $args[7]
})
}
# ------------------------- Get tenant domains ------------------------
$domains = Get-MgDomain -All | Where-Object {
$name = $_.Id
$isExcluded = $false
foreach ($pattern in $ExcludePatterns) {
if ($name -like $pattern) { $isExcluded = $true }
}
(-not $isExcluded) -and $_.IsVerified
}
Write-Host "Domains to check: $($domains.Count)" -ForegroundColor Cyan
# ---------------------------- Main loop ------------------------------
foreach ($domain in $domains) {
$domainName = $domain.Id
Write-Host "Checking $domainName ..." -ForegroundColor Yellow
# ---- Expected records from Microsoft 365
try {
$expectedRecords = Get-MgDomainServiceConfigurationRecord -DomainId $domainName -All -ErrorAction Stop
} catch {
Write-Warning "Cannot read expected records for $domainName : $($_.Exception.Message)"
continue
}
foreach ($rec in $expectedRecords) {
# Skip optional records if requested
if ($rec.IsOptional -and -not $IncludeOptional) { continue }
$props = $rec.AdditionalProperties # type-specific values live here
$service = $rec.SupportedService # Email, Intune, OfficeCommunicationsOnline, ...
switch ($rec.RecordType) {
# ---------------- MX ----------------
"Mx" {
$expected = "$($props['preference']) $($props['mailExchange'])"
$live = & $resolveLive $rec.Label "MX" | Sort-Object Preference
$liveText = ($live | ForEach-Object { "$($_.Preference) $($_.NameExchange)" }) -join "; "
if (-not $live) {
$status = "Missing"
} elseif ($live.NameExchange -contains $props['mailExchange']) {
$status = "Match"
if ($live.Count -gt 1) { $status = "Match (multiple MX records)" }
} else {
$status = "Mismatch"
}
& $addRow $domainName $service "MX" $rec.Label $expected $liveText $status $rec.IsOptional
}
# ---------------- TXT ---------------
"Txt" {
$expected = $props['text']
$live = & $resolveLive $rec.Label "TXT"
$liveTxt = $live | ForEach-Object { $_.Strings -join "" }
if ($expected -like "v=spf1*") {
# SPF: pass if the single SPF record includes Microsoft
$liveSpf = $liveTxt | Where-Object { $_ -like "v=spf1*" }
if (-not $liveSpf) {
$status = "Missing"
} elseif (@($liveSpf).Count -gt 1) {
$status = "Mismatch (multiple SPF records)"
} elseif ($liveSpf -match "include:spf\.protection\.outlook\.com") {
$status = "Match"
} else {
$status = "Mismatch (Microsoft include missing)"
}
& $addRow $domainName $service "TXT (SPF)" $rec.Label $expected ($liveSpf -join "; ") $status $rec.IsOptional
} else {
# Other TXT (e.g. verification): exact match on any string
if ($liveTxt -contains $expected) {
$status = "Match"
} else {
$status = "Missing"
}
& $addRow $domainName $service "TXT" $rec.Label $expected ($liveTxt -join "; ") $status $rec.IsOptional
}
}
# --------------- CNAME --------------
"CName" {
$expected = $props['canonicalName']
$live = & $resolveLive $rec.Label "CNAME"
$liveHost = ($live | Select-Object -First 1).NameHost
if (-not $liveHost) {
$status = "Missing"
} elseif ($liveHost.TrimEnd('.') -eq $expected.TrimEnd('.')) {
$status = "Match"
} else {
$status = "Mismatch"
}
& $addRow $domainName $service "CNAME" $rec.Label $expected $liveHost $status $rec.IsOptional
}
# ---------------- SRV ---------------
"Srv" {
# DNS name = _service._protocol.label
$srvName = "$($props['service']).$($props['protocol']).$($rec.Label)"
$expected = "$($props['priority']) $($props['weight']) $($props['port']) $($props['nameTarget'])"
$live = & $resolveLive $srvName "SRV" | Select-Object -First 1
if (-not $live) {
$status = "Missing"
$liveText = ""
} else {
$liveText = "$($live.Priority) $($live.Weight) $($live.Port) $($live.NameTarget)"
if (($live.NameTarget.TrimEnd('.') -eq $props['nameTarget'].TrimEnd('.')) -and ($live.Port -eq $props['port'])) {
$status = "Match"
} else {
$status = "Mismatch"
}
}
& $addRow $domainName $service "SRV" $srvName $expected $liveText $status $rec.IsOptional
}
# -------------- Anything else -------
default {
& $addRow $domainName $service $rec.RecordType $rec.Label "" "" "Info (not checked)" $rec.IsOptional
}
}
}
# ---- Extra check: SPF DNS lookup count (include, a, mx, ptr, exists, redirect)
$spfLive = (& $resolveLive $domainName "TXT" | ForEach-Object { $_.Strings -join "" }) | Where-Object { $_ -like "v=spf1*" } | Select-Object -First 1
if ($spfLive) {
$lookupCount = ([regex]::Matches($spfLive, '(?i)\b(include:|a\b|a:|mx\b|mx:|ptr|exists:|redirect=)')).Count
if ($lookupCount -gt $SpfLookupLimit) {
$status = "Mismatch (top-level lookups $lookupCount > $SpfLookupLimit)"
} else {
$status = "Info (top-level lookups: $lookupCount)"
}
& $addRow $domainName "Email" "TXT (SPF lookups)" $domainName "<= $SpfLookupLimit lookups" $spfLive $status $true
}
# ---- Extra check: DKIM selectors
if ($CheckDkim) {
foreach ($selector in @("selector1", "selector2")) {
$dkimName = "$selector._domainkey.$domainName"
$dkimLive = (& $resolveLive $dkimName "CNAME" | Select-Object -First 1).NameHost
if ($dkimLive) {
$status = "Match (CNAME present)"
} else {
$status = "Missing"
}
& $addRow $domainName "Email" "CNAME (DKIM)" $dkimName "Value from Defender portal" $dkimLive $status $true
}
}
# ---- Extra check: DMARC
if ($CheckDmarc) {
$dmarcName = "_dmarc.$domainName"
$dmarcLive = (& $resolveLive $dmarcName "TXT" | ForEach-Object { $_.Strings -join "" }) | Where-Object { $_ -like "v=DMARC1*" } | Select-Object -First 1
if (-not $dmarcLive) {
$status = "Missing"
} elseif ($dmarcLive -match "p=reject") {
$status = "Match (p=reject)"
} elseif ($dmarcLive -match "p=quarantine") {
$status = "Match (p=quarantine)"
} else {
$status = "Info (p=none - monitoring only)"
}
& $addRow $domainName "Email" "TXT (DMARC)" $dmarcName "v=DMARC1; p=quarantine|reject" $dmarcLive $status $true
}
}
# ------------------------------ Output -------------------------------
# On-screen overview
$report | Format-Table Domain, Service, Type, Name, Status -AutoSize
# CSV export with timestamp
$csvPath = Join-Path $ExportFolder ("DomainDnsReport_{0:yyyyMMdd_HHmm}.csv" -f (Get-Date))
$report | Export-Csv -Path $csvPath -NoTypeInformation -Encoding UTF8
Write-Host "Report saved to: $csvPath" -ForegroundColor Green
# Summary counts per status
Write-Host "`n----- Status summary -----" -ForegroundColor Cyan
$report | Group-Object { ($_.Status -split ' ')[0] } | Select-Object Name, Count | Format-Table -AutoSize
# Highlight required records that need attention
$issues = $report | Where-Object { ($_.Status -like "Missing*" -or $_.Status -like "Mismatch*") -and (-not $_.Optional) }
if ($issues) {
Write-Host "Required records needing review:" -ForegroundColor Red
$issues | Format-Table Domain, Type, Name, Expected, Live -AutoSize
} else {
Write-Host "All required records match Microsoft 365 expectations." -ForegroundColor Green
}
# ----------------------------- Clean up ------------------------------
Disconnect-MgGraph | Out-Null