Article

Mastering Email Infrastructure: A Step-by-Step Guide to DNS Email Records & Cloudflare Configuration

A production runbook for configuring and migrating email DNS records. Learn how to extract MX, SPF, and DKIM records from cPanel, publish to Cloudflare DNS with unproxied Gray Cloud status, and verify resolution using PowerShell and dig.

8 min read

Verified on: Cloudflare DNS Manager, cPanel Zone Editor, Windows PowerShell 7, BIND 9

Contents
  1. 2. Technical Breakdown: MX, SPF, DKIM & DMARC Records
  2. 2.1 MX (Mail Exchanger) Records
  3. 2.2 SPF (Sender Policy Framework) Records
  4. 2.3 DKIM (DomainKeys Identified Mail) Records
  5. 2.4 DMARC & Policy Staging
  6. 3. Step-by-Step Walkthrough: Migrating from cPanel to Cloudflare DNS
  7. Phase 1: Extracting Record Values from cPanel
  8. Phase 2: Manual Record Publishing in Cloudflare DNS
  9. Special Dashboard Behaviors & Architecture Patterns
  10. 4. Post-Configuration Verification Best Practices
  11. 4.1 Verification via Windows PowerShell
  12. 4.2 Verification via Command Prompt (nslookup)
  13. 4.3 Verification via Linux & macOS (dig)
  14. 4.4 End-to-End Delivery & Message Header Inspection
  15. 5. Operational Risks of Misconfiguration
  16. 6. Related Runbooks & Field Guides
WatchMastering Email Infrastructure: A Step-by-Step Guide to DNS Email Records & Cloudflare Configuration

[!NOTE] Looking for the cryptographic theory and compliance mandates (CISA BOD 18-01 / PCI DSS 4.0.1)? Read the companion architecture guide: Email Authentication & Security Protocols: STARTTLS, SPF, DKIM, DMARC & ARC.

Migrating email DNS records or configuring a new domain in Cloudflare is one of the quickest ways to cause an unintended production outage if done carelessly. A single accidental “Orange Cloud” proxy toggle on a mail record breaks SMTP handshakes, publishing multiple SPF TXT records throws instant PermError failures across Microsoft 365 and Google Workspace, and missing DKIM keys sends legitimate transactional email straight to spam.

This runbook focuses strictly on hands-on execution: extracting legacy records from cPanel, publishing DNS records correctly in Cloudflare with unproxied Gray Cloud status, and verifying resolution end-to-end using PowerShell and native command-line tooling.


2. Technical Breakdown: MX, SPF, DKIM & DMARC Records

Securing and operating email infrastructure requires four foundational record types working in synchronization:

Record Name DNS Record Type Primary Operational Function Key Parameters & Syntax Components
MX (Mail Exchanger) MX Inbound Mail Routing Priority value (e.g., 10, 20), Target server FQDN (e.g., route1.mx.cloudflare.net)
SPF (Sender Policy Framework) TXT Sender Source Authorization Version tag (v=spf1), Authorized IPs (ip4:), Includes (include:), Qualifier (~all, -all)
DKIM (DomainKeys Identified Mail) TXT or CNAME Cryptographic Message Signing Selector prefix (e.g., s1._domainkey), Version (v=DKIM1), Key type (k=rsa), Public key string
DMARC (Reporting & Conformance) TXT Alignment & Handling Enforcement Version (v=DMARC1), Policy (p=none, quarantine, reject), Reporting URI (rua=mailto:...)

2.1 MX (Mail Exchanger) Records

MX records specify which mail servers receive inbound email sent to your domain.

Routing Breakdown How MX Records Route Your Email
  • Host / Name: @ or root domain (example.com). Subdomains use the sub-identifier (mail or inbound).
  • Destination / Mail Server: The FQDN of the receiving mail server (e.g., route1.mx.cloudflare.net). MX targets must resolve to an A or AAAA record; they cannot point directly to an IP address.
  • Priority: Lowest numerical value takes precedence (e.g., priority 10 receives mail first; 20 and 50 act as fallback gateways).

2.2 SPF (Sender Policy Framework) Records

Published as a DNS TXT record, SPF authorizes specific IP addresses and mail providers to emit mail using your domain in the SMTP envelope.

  • Version Tag (v=spf1): Required prefix.
  • Mechanisms: ip4:x.x.x.x (authorized IPs) and include:_spf.example.com (authorized third-party services like Google, M365, or Cloudflare).
  • Enforcement: ~all (SoftFail, recommended during migrations) or -all (HardFail, rejects unlisted sources).

[!CAUTION] The Multiple SPF Record Trap: A domain must NEVER have more than one SPF TXT record published. If multiple SPF records are detected on a single zone, receiving MTAs immediately throw a PermError (Permanent Failure) and evaluate the SPF check as failed. To authorize multiple services, consolidate all IP mechanisms and include: directives into a single unified record:

v=spf1 ip4:198.51.100.1 include:_spf.mx.cloudflare.net include:amazonses.com ~all

2.3 DKIM (DomainKeys Identified Mail) Records

DKIM publishes the public half of an asymmetric key pair so recipient servers can verify digital signatures on outbound messages.

  • Selector Namespace: Published under a selector prefix (e.g., s1._domainkey.example.com or cf-bounce._domainkey.example.com), allowing seamless key rotation without touching other mail streams.
  • Integrity Check: The sending server signs message headers with its private key; the receiving MTA queries DNS for the matching public key in p=... to verify the body and headers were not tampered with in transit.

2.4 DMARC & Policy Staging

DMARC ties SPF and DKIM validation results directly to the visible From: header in the user’s email client:

graph LR
    A["Monitoring Mode: p=none"] -->|Analyze Daily XML Telemetry| B["Quarantine Mode: p=quarantine"]
    B -->|Mitigate Edge Cases & False Positives| C["Full Enforcement: p=reject"]
  • p=none (Monitoring): Delivers email normally while receiving servers send daily XML telemetry (rua) to audit all sending sources.
  • p=quarantine: Diverts unauthenticated mail away from the inbox into recipient spam/junk folders.
  • p=reject: Blocks unauthenticated and spoofed messages outright at the recipient gateway.

3. Step-by-Step Walkthrough: Migrating from cPanel to Cloudflare DNS

A standard systems administration scenario involves migrating email DNS records from a shared cPanel hosting provider to an enterprise Anycast DNS network like Cloudflare.

graph TD
    A["cPanel Zone Editor"] -->|"1. Extract MX, SPF, DKIM Values"| B["Local Staging Notepad / Runbook"]
    B -->|"2. Create MX Records with Priority Numbers"| C["Cloudflare DNS Manager"]
    B -->|"3. Consolidate & Publish Unified SPF TXT"| C
    B -->|"4. Publish DKIM Selector TXT / CNAME"| C
    C -->|"5. Enforce Unproxied Gray Cloud Status"| D["Public Anycast DNS Edge: DNS Only"]

[!CAUTION] The Cloudflare Proxy Status Trap (Orange Cloud vs. Grey Cloud): When creating email DNS records (MX, SPF, DKIM, DMARC) in Cloudflare, all records must ALWAYS remain set to DNS Only (Grey cloud). Cloudflare’s HTTP/HTTPS reverse proxy network terminates web traffic (ports 80/443) and does not route raw mail protocols (SMTP ports 25/587, IMAP port 993). Enabling the proxy (Orange cloud) on mail hostnames or DKIM records causes public resolvers to receive Cloudflare Anycast web proxy IPs rather than raw mail records, breaking email delivery instantly.


Phase 1: Extracting Record Values from cPanel

  1. Log in to your cPanel management dashboard.
  2. Under the Domains section, select Zone Editor.
  3. Locate your target domain and click Manage.
  4. Filter by record type and extract:
    • MX Record: Note the Host (e.g., @), Target server (e.g., mail.example.com), and Priority (e.g., 0 or 10).
    • SPF Record: Copy the complete TXT content starting with v=spf1.
    • DKIM Record: Locate the record under default._domainkey or custom selector and copy the full public key string.

Phase 2: Manual Record Publishing in Cloudflare DNS

Log in to the Cloudflare Dashboard, select your domain, and navigate to DNS ➔ Records ➔ Add record.

1. Adding Inbound MX Records

  1. Set Type to MX.
  2. Enter Name: @ (represents root domain).
  3. Enter Mail server: route1.mx.cloudflare.net (or your primary mail exchange FQDN).
  4. Set TTL to Auto.
  5. Enter Priority: 10.
  6. Click Save.
  7. Repeat the procedure for secondary and tertiary exchangers (e.g., priority 20, 30).

2. Adding the SPF TXT Record

  1. Click Add record.
  2. Set Type to TXT.
  3. Enter Name: @.
  4. Enter TTL: Auto.
  5. In Content, paste your consolidated SPF policy string:
    v=spf1 include:_spf.mx.cloudflare.net ~all
  6. Click Save.

3. Adding DKIM Cryptographic Key Records

  1. Click Add record.
  2. Set Type to TXT (or CNAME if delegating to AWS SES or Microsoft 365).
  3. In Name, enter the selector prefix (e.g., cf-bounce._domainkey).
  4. Set TTL: Auto.
  5. In Content, paste the complete DKIM public key payload:
    v=DKIM1; h=sha256; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
  6. Ensure Proxy status is disabled (DNS Only / Grey Cloud).
  7. Click Save.

Special Dashboard Behaviors & Architecture Patterns

  • Propagation Speed: DNS modifications published through Cloudflare’s Anycast edge propagate globally in 5 to 15 minutes, compared to legacy nameservers that can take up to 24 hours.
  • Separation of Root Domain Routing vs. Subdomain Sending: Enterprise infrastructures decouple high-volume outbound mail from root domain routing. Inbound messages route to user inboxes via root MX records (example.com), while transactional sending and automated bounce processing occur on an isolated subdomain (e.g., cf-bounce.example.com). This prevents outbound deliverability hiccups from disrupting organizational communication.
  • Cloudflare Locked DNS Records: Managed services (such as Cloudflare Email Routing or SES integrations) often apply a Locked tag to system-generated records. This safeguards critical mail routing records against accidental deletion or modification by junior administrators.

4. Post-Configuration Verification Best Practices

After publishing DNS records, systematic command-line verification ensures that records resolve publicly and return zero formatting errors.

4.1 Verification via Windows PowerShell

Use the native Resolve-DnsName cmdlet in Windows PowerShell 7 or Windows Terminal:

# 1. Inspect MX Records and Priority Values
Resolve-DnsName -Name "example.com" -Type MX | Format-Table Name, NameExchange, Preference, TTL

# 2. Inspect SPF TXT Record
Resolve-DnsName -Name "example.com" -Type TXT | Where-Object { $_.Strings -like "v=spf1*" } | Select-Object -ExpandProperty Strings

# 3. Inspect DKIM Selector Record
Resolve-DnsName -Name "cf-bounce._domainkey.example.com" -Type TXT | Select-Object -ExpandProperty Strings

# 4. Inspect DMARC Policy Record
Resolve-DnsName -Name "_dmarc.example.com" -Type TXT | Select-Object -ExpandProperty Strings

4.2 Verification via Command Prompt (nslookup)

:: 1. Query MX Records
nslookup -type=MX example.com

:: 2. Query SPF Records
nslookup -type=TXT example.com

:: 3. Query DKIM Selector Record
nslookup -type=TXT cf-bounce._domainkey.example.com

:: 4. Query DMARC Policy Record
nslookup -type=TXT _dmarc.example.com

4.3 Verification via Linux & macOS (dig)

# 1. Query MX records with clean formatting
dig MX example.com +short

# 2. Query SPF TXT record
dig TXT example.com +short | grep "v=spf1"

# 3. Query DKIM public key
dig TXT cf-bounce._domainkey.example.com +short

# 4. Query DMARC policy
dig TXT _dmarc.example.com +short

4.4 End-to-End Delivery & Message Header Inspection

  1. Send Test Inbound & Outbound Messages: Transmit test emails to external providers (Gmail, Outlook, iCloud) and internal mailboxes.
  2. Inspect Raw Authentication Headers: View original message headers and verify the presence of explicit PASS results:
    Authentication-Results: mx.google.com;
           dkim=pass [email protected] header.s=cf-bounce;
           spf=pass (google.com: domain of [email protected] designates 198.51.100.1 as permitted sender) [email protected];
           dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=example.com
  3. Monitor Aggregate XML Reports (rua): Confirm that daily aggregate reports arrive at your designated reporting mailbox to maintain visibility over unauthorized spoofing attempts.

5. Operational Risks of Misconfiguration

Failing to properly configure and audit email DNS records introduces critical failure modes:

  • Complete Deliverability Drop: Syntax errors, extra spaces, or duplicate SPF records generate immediate PermError flags, routing legitimate business communication to spam or dropping connections at the SMTP gateway.
  • Domain Impersonation & BEC Scams: Publishing records without an enforced DMARC policy (p=quarantine or p=reject) leaves your exact domain open to Business Email Compromise (BEC) and executive spoofing.
  • Regulatory Non-Compliance: Non-compliant domains violate PCI DSS v4.0.1 audit standards, jeopardizing merchant payment processing capabilities, or run afoul of federal mandates like CISA BOD 18-01.