PromptCode reviewOpen

DNS Zone Record Linter

- name: dns-zone-record-linter description: Lints a DNS zone file or a provider's CSV record export before it breaks web or mail - CNAME at the apex or next to other records, MX/NS pointing at a CNAME or IP, missing trailing dots, missing or duplicate SPF, +all/?all and the 10-lookup limit, DMARC

Front matter
name: DNS Zone Record Linter
description: - name: dns-zone-record-linter description: Lints a DNS zone file or a provider's CSV record export before it breaks web or mail - CNAME at the apex or next to other records, MX/NS pointing at a CNAME or IP, missing trailing dots, missing or duplicate SPF, +all/?all and the 10-lookup limit, DMARC
kind: Prompt

DNS Zone Record Linter


name: dns-zone-record-linter description: Lints a DNS zone file or a provider's CSV record export before it breaks web or mail - CNAME at the apex or next to other records, MX/NS pointing at a CNAME or IP, missing trailing dots, missing or duplicate SPF, +all/?all and the 10-lookup limit, DMARC and DKIM presence, syntax and key size, TTL extremes, private IPs and SOA mistakes. Returns corrected records. Includes an offline stdlib Python linter with --self-test. ---

DNS Zone Record Linter

You review DNS records the way a careful DNS operator would before a migration or a mail setup goes live. You find the mistakes that silently break things (a CNAME at the apex, an MX that points at a CNAME, mail.example.com written without its trailing dot, two SPF records), explain the effect in plain words, and hand back corrected records. You work offline from the file; you never claim a live lookup you did not make.

Files in this skill

  • scripts/dns_lint.py - parses a BIND zone file ($ORIGIN, $TTL, @, relative names, multi-line SOA, quoted TXT) or a CSV export (name,type,value,ttl,priority) and reports findings with line numbers, then lists out-of-zone targets to check live (Python 3.8+ standard library only)
  • references/record-rules.md - the rules behind each check with RFC pointers: CNAME exclusivity, MX/NS targets, trailing dots, SPF, DMARC, DKIM, TTL and SOA values
  • references/finding-codes.md - every finding code with severity, when it is acceptable, and the usual fix
  • templates/dns-review.md - the review to hand back (summary, fixes as records, live checks, rollout notes)
  • examples/example.com.zone - a zone exported before a DNS host move, with mistakes on purpose
  • examples/example.com.fixed.zone - the corrected zone (lints clean)
  • examples/lint-report.md - the real output of the linter on the broken example

Workflow

1. Get the records and the context

Ask for the zone file (BIND format, dig AXFR output or the provider's export) or a CSV (name,type,value,ttl,priority), the zone name, and what the domain is for: website only, sending mail (which services: Google Workspace, Microsoft 365, a newsletter tool, a helpdesk), or no mail at all. If the user pastes records from a provider UI, note that host names there usually have no trailing dot and that NS/SOA are often managed by the provider.

2. Run the linter

python3 scripts/dns_lint.py examples/example.com.zone
python3 scripts/dns_lint.py records.csv --origin example.com
python3 scripts/dns_lint.py zone.db --origin example.com --min-severity MEDIUM --ignore CAA_MISSING --json
python3 scripts/dns_lint.py --self-test

Exit 0 = no HIGH findings, 1 = HIGH findings, 2 = bad input (unclosed parenthesis or quote, unknown zone name). If you cannot run code, apply references/record-rules.md by hand in the same order.

3. Read the findings

  • HIGH breaks resolution or mail now (CNAME conflicts, MX to CNAME, missing trailing dot, two SPF records, +all, DMARC at the wrong name, invalid SPF terms, weak DKIM key).
  • MEDIUM is wrong or risky but may still work (missing DMARC/DKIM/SPF, ?all, private IPs, TTL extremes, dangling targets, a single name server).
  • LOW is hygiene (duplicates, p=none, 1024-bit DKIM, no CAA, obsolete SPF type).
  • The linter counts only top-level SPF lookups; nested includes add more. It cannot see records that live at the provider (DKIM selectors created by a mail host) or targets outside the zone. Say so, and list the live checks from the "Out-of-zone targets" table (dig +short CNAME shop.example.com, dig TXT _dmarc.example.com).

4. Deliver

Fill templates/dns-review.md: a short summary, the corrected records in the user's format (zone lines or provider form fields), what to verify live, and the rollout order: lower TTLs a day ahead, change, verify, raise TTLs again; bump the SOA serial. For mail changes, recommend DMARC p=none with rua first, then quarantine, then reject once reports are clean.

Example result

On examples/example.com.zone the linter reports 19 findings (HIGH 7, MEDIUM 8, LOW 4): the website was moved with @ CNAME bakery-site.example.net. (CNAME at the apex, next to SOA, NS, MX and TXT), www has both a CNAME and a verification TXT, MX 10 mail.example.com lacks its trailing dot so it means mail.example.com.example.com., the backup MX points at a CNAME, there are two v=spf1 records (one with ?all), DMARC sits at dmarc instead of _dmarc, an old DKIM selector is revoked, the SOA contact contains @, and intranet publishes 10.0.4.12. examples/example.com.fixed.zone fixes all of them and lints clean (exit 0).

Rules

  • Never invent record values (IPs, DKIM keys, provider host names); use placeholders and say what the user must copy from the provider.
  • Keep exactly one SPF record per name; merge includes instead of adding a second record.
  • Do not suggest deleting DKIM selectors or MX records that may still be in use without asking which services send mail.
  • Explain trailing-dot effects with the expanded name, so the user sees the bug.
  • Mark anything that needs a live lookup as "to verify"; never present it as checked.
  • Changes to NS, MX or apex records go with a rollout and rollback note (old values, TTLs, when to check).

FILE:references/record-rules.md

DNS record rules the linter applies

Names and trailing dots

  • In a zone file a name without a final dot is relative: www and mail.example.com both get the origin appended. mail.example.com in zone example.com. becomes mail.example.com.example.com. - the most common copy-paste bug. Write mail.example.com. or just mail.
  • @ is the origin (apex). A line starting with whitespace reuses the previous owner name.
  • Provider web forms usually add the dot for you; the linter skips trailing-dot checks for CSV input.

CNAME (RFC 1034 3.6.2, RFC 2181 10.1)

  • A name with a CNAME may have no other data (only DNSSEC records). Resolvers return the CNAME and ignore the rest, so a TXT or MX next to it is invisible or breaks.
  • The apex always has SOA and NS, so a CNAME at the apex is never valid. Use A/AAAA, or the provider's ALIAS / ANAME / CNAME flattening, which answers with A/AAAA.
  • Only one CNAME per name. Chains (CNAME to CNAME) work but cost lookups; keep them short.
  • A CNAME to an outside service (shop, status page, CDN) that is later cancelled can be claimed by someone else (subdomain takeover). List them and remove the ones no longer used.

MX, NS, SRV targets (RFC 2181 10.3, RFC 5321 5.1, RFC 7505)

  • MX, NS and SRV must name a host with A/AAAA records, not a CNAME and not an IP address.
  • Lower MX preference wins. Backup MX hosts must accept mail for the domain or they only collect spam.
  • Null MX MX 0 . says the domain receives no mail. It must be the only MX.
  • Use at least two NS on separate networks; the NS set at the registrar (delegation) must match the zone.

SPF (RFC 7208)

  • One v=spf1 TXT record per name. Two records = permerror = SPF fails for all mail.
  • Terms: ip4:, ip6:, a, mx, include:, exists:, ptr (deprecated), all, modifiers redirect= and exp=. Qualifiers: + pass (default), - fail, ~ softfail, ? neutral.
  • Max 10 terms that cause DNS lookups (include, a, mx, ptr, exists, redirect), counted across nested includes. ip4/ip6 cost nothing.
  • End with -all (or ~all while testing). +all lets anyone send as you; ?all gives no signal. Terms after all are ignored.
  • The SPF record type (99) is obsolete; publish TXT only.
  • One quoted string holds at most 255 bytes; long records are written as "part one" "part two" and are joined without spaces.

DMARC (RFC 7489)

  • TXT at _dmarc.<domain> only. Must start with v=DMARC1; and include p=none|quarantine|reject. One record.
  • Add rua=mailto: to get aggregate reports. Roll out p=none -> quarantine -> reject; pct below 100 applies the policy to part of the mail.
  • Since 2024 Gmail and Yahoo require SPF, DKIM and DMARC (at least p=none) for bulk senders.

DKIM (RFC 6376, RFC 8301, RFC 8463)

  • Keys live at <selector>._domainkey.<domain> as TXT (v=DKIM1; k=rsa; p=<base64>) or as a CNAME to the provider (Microsoft 365, many ESPs).
  • RSA keys under 1024 bits must not be used; 2048 bits is the recommendation. Ed25519 (k=ed25519) can be added alongside RSA.
  • Empty p= means revoked. Selectors are not discoverable: absence in a file means "not here", not "not anywhere".

TTL and SOA (RFC 1035, RFC 2181 8, RFC 2308)

  • TTL is 0..2147483647 s. Usual values: 300-3600 s for records that change, 3600-86400 s for stable ones. Below 60 s many resolvers raise it anyway; above a week, a mistake lingers a week. Lower the TTL a day before a planned change.
  • $TTL sets the default. The SOA minimum field is the negative-caching TTL (how long "does not exist" is cached): 300-3600 s.
  • The SOA contact (rname) is an email written with a dot: hostmaster.example.com. for [email removed].
  • Bump the SOA serial on every change (YYYYMMDDnn).

Addresses and CAA

  • A holds IPv4, AAAA holds IPv6. Private, loopback and link-local addresses do not belong in a public zone (use split-horizon DNS). Documentation ranges (192.0.2.0/24, 2001:db8::/32) are fine in examples.
  • CAA (RFC 8659) limits which certificate authorities may issue for the domain: @ CAA 0 issue "letsencrypt.org".

FILE:references/finding-codes.md

Finding codes

CodeSevProblemAcceptable whenUsual fix
CNAME_AT_APEXHIGHapex CNAME conflicts with SOA/NS, breaks mailneverA/AAAA or provider ALIAS/flattening
CNAME_WITH_OTHER_DATAHIGHother records next to a CNAME are ignoredDNSSEC records onlymove the TXT/MX elsewhere or use A/AAAA
MULTIPLE_CNAMEHIGHtwo CNAMEs for one nameneverkeep one
MX_TO_CNAME / NS_TO_CNAMEHIGHMX/NS/SRV target is an aliasnever (some servers tolerate it, many do not)point at the final A/AAAA host
TARGET_IS_IPHIGHMX/NS/CNAME value is an IPneverhost name with an A record
MISSING_TRAILING_DOTHIGHfull name without dot gets the origin appendedneveradd the dot or write it relative
OWNER_DOUBLED_ORIGINHIGHowner www.example.com without dotneverwww or www.example.com.
SPF_MULTIPLEHIGHtwo v=spf1 records -> permerrornevermerge into one
SPF_PASS_ALLHIGH+all/all authorizes everyonenever-all / ~all
SPF_SYNTAXHIGHunknown term or bad ip4/ip6 -> permerrorneverfix the term
SPF_TOO_MANY_LOOKUPSHIGHmore than 10 lookup termsneverflatten, remove unused includes
TXT_STRING_TOO_LONGHIGHa quoted string over 255 bytesprovider UIs split for you (CSV input is not checked)split into chunks
DMARC_WRONG_NAMEHIGHv=DMARC1 not at _dmarcnevermove to _dmarc
DMARC_MULTIPLE / DMARC_SYNTAXHIGHreceivers ignore DMARCneverone valid record
DKIM_WRONG_NAME / DKIM_BAD_KEYHIGHkey cannot be found or parsednevercopy again from the provider
DKIM_WEAK_KEYHIGHRSA key below 1024 bitsneverrotate to 2048
SOA_RNAME_ATHIGH@ in the SOA contactneverhostmaster.example.com.
NULL_MX_WITH_OTHERSHIGHMX 0 . plus real MXneverone or the other
BAD_ADDRESS / WRONG_ADDRESS_FAMILY / TTL_INVALIDHIGHvalue cannot be loadedneverfix the value
SPF_MISSINGMEDIUMMX but no SPFnever for a mail domainone SPF record
DMARC_MISSINGMEDIUMmail domain without DMARCneverv=DMARC1; p=none; rua=... then tighten
DKIM_NOT_FOUNDMEDIUMno selector in this fileselectors hosted elsewhere (check live)publish the provider's selector
DKIM_REVOKEDMEDIUMp= emptyintentionally retired selector (then remove it)remove or publish the new key
SPF_NEUTRAL_ALL / SPF_NO_ALL / SPF_TERMS_AFTER_ALLMEDIUMweak or ignored policyshort test phaseend with -all / ~all
MAYBE_MISSING_TRAILING_DOTMEDIUMlooks like an outside name without dotit really is a relative nameadd the dot
DANGLING_TARGETMEDIUMin-zone target has no recordsdefined in another file or viewadd or fix
MX_TARGET_NO_ADDRESSMEDIUMmail host has no A/AAAAaddress comes from another zoneadd A/AAAA
PRIVATE_ADDRESSMEDIUMRFC 1918/loopback/link-local in public DNSdeliberately internal-only zonesplit-horizon
TTL_TOO_LOW / TTL_TOO_HIGHMEDIUMbelow 60 s / above 7 daysshort TTL during a planned cut-over; _acme-challenge300 s - 1 day
NS_MISSING / NS_SINGLE / SOA_MISSINGMEDIUMincomplete zone fileprovider-managed NS/SOA (CSV input skips these)add them
UNKNOWN_TYPEMEDIUMrecord type not recognizednew type the script does not knowcheck spelling
SPF_PTR / SPF_TYPE99 / SPF_LOOKUPS_NEAR_LIMITLOWdeprecated or close to the limit-replace / count nested includes live
DMARC_MONITOR_ONLY / DMARC_NO_RUA / DMARC_PARTIAL_PCTLOWDMARC not yet enforcing or not reportingduring rollouttighten after reviewing reports
DKIM_1024_KEYLOW1024-bit RSAprovider does not offer 2048rotate when possible
NO_MAIL_POLICY / NULL_MX_SPF_NOT_FAILLOWno-mail domain can be spoofed-null MX + v=spf1 -all + DMARC reject
CNAME_CHAIN / DUPLICATE_RECORD / CAA_MISSING / NO_DEFAULT_TTL / SOA_NEGATIVE_TTL_HIGH / INCLUDE_NOT_FOLLOWEDLOWhygiene-see the fix column in the report

Exit codes: 0 = no HIGH, 1 = HIGH present, 2 = bad input. In CI, gate on HIGH and keep any --ignore list in the repo with a reason.

Live checks the linter cannot do (offline)

  • Out-of-zone targets: dig +short A <target>; a CNAME to a cancelled SaaS host is a takeover risk.
  • Nested SPF includes: count with dig TXT <include> recursively, or a resolver-based SPF checker.
  • DKIM selectors hosted by the mail provider: dig TXT <selector>._domainkey.<domain> (Google: google, Microsoft 365: selector1/selector2 CNAMEs).
  • Delegation: dig NS <domain> @a.gtld-servers.net (or the TLD's servers) must match the zone's NS set.

FILE:templates/dns-review.md

DNS review: <domain>

Source: <zone file / provider export, date> Purpose: <website + Google Workspace mail + newsletter tool> Result: <HIGH n, MEDIUM n, LOW n> - <one-sentence verdict, e.g. "mail delivery is at risk until SPF is merged and MX is fixed">

Fix now (HIGH)

#Record nowProblemReplace with
1<@ CNAME bakery-site.example.net.><CNAME at apex hides MX/TXT><@ A 192.0.2.10> (or ALIAS at the provider)
2<@ MX 10 mail.example.com><no trailing dot -> mail.example.com.example.com.><@ MX 10 mail.example.com.>

Fix soon (MEDIUM)

  • <add _dmarc TXT v=DMARC1; p=none; rua=mailto:dmarc-reports@<domain>>

Hygiene (LOW)

  • <remove duplicate A for blog; add CAA>

Mail authentication summary

CheckNowAfter the fix
SPF<2 records, ?all><1 record, includes A + B, -all>
DKIM<google selector 1024-bit, s2019 revoked><2048-bit key, retired selector removed>
DMARC<wrong name><_dmarc p=none -> quarantine on <date>>

Verify live (not checked offline)

  • <dig +short CNAME shop.<domain>> - <target still in use?>
  • <dig TXT google._domainkey.<domain>> - <matches the provider console?>

Rollout

  1. <lower TTL of changed records to 300 s, wait one old TTL>
  2. <apply changes, bump SOA serial to YYYYMMDDnn>
  3. <verify with dig against the authoritative servers and a public resolver; send a test mail and read the Authentication-Results header>
  4. <raise TTLs back to 3600 s; review DMARC reports after 1-2 weeks>

Rollback: <old values listed above; restore them and wait one TTL> Open questions: <which services send mail as this domain? is backupmx still used?> FILE:examples/example.com.zone ; example.com - zone exported before the move to a new DNS host (has mistakes on purpose) $ORIGIN example.com. $TTL 3600 @ IN SOA ns1.example.net. [email removed]. ( 2026103001 ; serial 7200 ; refresh 900 ; retry 1209600 ; expire 172800 ) ; minimum (negative caching) @ IN NS ns1.example.net. @ IN NS ns2.example.net.

; website moved to a static host @ IN CNAME bakery-site.example.net. www 30 IN CNAME bakery-site.example.net. www IN TXT "site-verification=4f9c2a" shop IN CNAME shops.myshopify.com blog IN A 192.0.2.44 blog IN A 192.0.2.44 legacy 1209600 IN A 192.0.2.45 intranet IN A 10.0.4.12

; mail @ IN MX 10 mail.example.com @ IN MX 20 backupmx backupmx IN CNAME mx2.example.net. @ IN TXT "v=spf1 include:_spf.google.com ~all" @ IN TXT "v=spf1 include:sendgrid.net ?all" dmarc IN TXT "v=DMARC1; p=none" google._domainkey IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDbNfaf4mo/6FvrWAv3WssXhXwsdrJxrAuhIVcYXdrMZp55PDpEjo63C/vOuaStp58YtZTnzQlm0V3rjtvOP1XgGAy3LWurXdRkT0zOGxx0AMgjZfD/8QDgjF6f4VW9zmNytbD3EgZXxeGZSBw8JtTdT/rOEygTgYL5+x5DftDSFQIDAQAB" s2019._domainkey IN TXT "v=DKIM1; k=rsa; p=" FILE:examples/example.com.fixed.zone ; example.com - corrected zone $ORIGIN example.com. $TTL 3600 @ IN SOA ns1.example.net. hostmaster.example.com. ( 2026103002 ; serial (bumped) 7200 ; refresh 900 ; retry 1209600 ; expire 3600 ) ; minimum (negative caching) @ IN NS ns1.example.net. @ IN NS ns2.example.net. @ IN CAA 0 issue "letsencrypt.org"

; website: A/AAAA at the apex (or the provider's ALIAS/flattening), CNAME only below it @ IN A 192.0.2.10 @ IN AAAA 2001:db8::10 www IN CNAME bakery-site.example.net. _site-verification.www IN TXT "site-verification=4f9c2a" shop IN CNAME shops.myshopify.com. blog IN A 192.0.2.44 legacy IN A 192.0.2.45 ; intranet moved to the internal (split-horizon) view

; mail @ IN MX 10 mail.example.com. @ IN MX 20 mx2.example.net. mail IN A 192.0.2.25 @ IN TXT "v=spf1 include:_spf.google.com include:sendgrid.net -all" _dmarc IN TXT "v=DMARC1; p=quarantine; rua=mailto:[email removed]" google._domainkey IN TXT ( "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz7ouq6bH4GbHRPASRa3m/LiSvOKSZ7L7KZqE231EHY1s8FN9criBQkJXXmxkwPERQSVSyRIC4LjSpxwPTe6LEVhg7nrswTX1ktBbXMUmkgj8CPKV+yWzOsDOMk7kjqghuNWXD/R5K/mT7xbTiCaXztegoQi+" "kVXf0xuMmQYLxVthdjIz1h2PORFhtjzwKYbpaMKjq2BWKIaNtaGBxc2kaSLyPw8W65+A7XeLhtKT8zcteU72IpdmibNsHlkBR0Hb7rQgb+0LgNVqPvF/mm37PKFPQPrfWjjL/Fc1MQoCm8jO3kI0O5ssuP7KKO7ZjtT4ekeHytw23INuPh/Kw1LqzwIDAQAB" ) FILE:examples/lint-report.md

DNS record lint: example.com.zone

Zone: example.com. Format: zone Records: 19 Findings: 19 (HIGH 7, MEDIUM 8, LOW 4)

SevCodeLineNameTypeProblemFix
HIGHSOA_RNAME_AT4@SOAcontact '[email removed].' contains '@'; in DNS it is written with a dotwrite the contact as hostmaster.example.com. (first @ becomes a dot)
LOWSOA_NEGATIVE_TTL_HIGH4@SOASOA minimum 172800 s: a deleted-then-added name stays 'does not exist' in caches that longset the SOA minimum (negative-caching TTL) to 300-3600 s
HIGHCNAME_AT_APEX14@CNAMECNAME at the zone apex conflicts with the SOA and NS records there; mail and other lookups breakuse A/AAAA records at the apex, or your provider's ALIAS/ANAME/CNAME-flattening record
HIGHCNAME_WITH_OTHER_DATA15wwwCNAMEname has a CNAME and also TXT; resolvers return only the CNAMEa name with a CNAME may have no other records: move the other records or replace the CNAME with A/AAAA
MEDIUMTTL_TOO_LOW15wwwCNAMETTL 30 s: extra query load, slower lookups, and many resolvers raise it anywayuse 300 s or more for normal records (lower only for a planned change)
MEDIUMMAYBE_MISSING_TRAILING_DOT17shopCNAME'shops.myshopify.com' looks like a full host name but has no trailing dot, so it means shops.myshopify.com.example.com.if this is an outside host name, add the trailing dot
LOWDUPLICATE_RECORD19blogAsame as line 18delete the duplicate
MEDIUMTTL_TOO_HIGH20legacyATTL 1209600 s (14 days): a wrong value stays cached that longuse 1 h to 1 day; above a week, mistakes take a week to undo
MEDIUMPRIVATE_ADDRESS21intranetA10.0.4.12 is a private/loopback address; outside users cannot reach it and it reveals internal layoutdo not publish private/loopback addresses in a public zone (use split-horizon DNS if needed)
HIGHMISSING_TRAILING_DOT24@MX'mail.example.com' has no trailing dot, so it means mail.example.com.example.com.end fully qualified names with a dot (mail.example.com.) or write the relative form (mail)
MEDIUMDANGLING_TARGET24@MXMX target mail has no records in this zoneadd the missing in-zone record or fix the target name
HIGHMX_TO_CNAME25@MXMX target backupmx is a CNAME (not allowed, RFC 2181 10.3)point MX at a name with A/AAAA records (the CNAME's final target)
HIGHSPF_MULTIPLE28@TXT2 v=spf1 records at this name (lines 27, 28)merge into ONE v=spf1 record; two records make every SPF check fail (permerror)
MEDIUMSPF_NEUTRAL_ALL28@TXT'?all' is neutral: unauthorized senders are not markeduse ~all or -all; ?all gives receivers no signal
HIGHDMARC_WRONG_NAME29dmarcTXTDMARC record is not at _dmarc.<domain>, so receivers never see itDMARC is only read from _dmarc.<domain>; move the record there
LOWDKIM_1024_KEY30google._domainkeyTXTRSA key is 1024 bits; 2048 is the current recommendationplan rotation to a 2048-bit key
MEDIUMDKIM_REVOKED31s2019._domainkeyTXTp= is empty: this selector is revoked and mail signed with it fails DKIMempty p= revokes the key; remove the record if the selector is retired, or publish the new key
MEDIUMDMARC_MISSING-_dmarcTXTno DMARC record: receivers cannot tell spoofed mail from yours, and Gmail/Yahoo require DMARC for bulk sendersadd TXT at _dmarc: "v=DMARC1; p=none; rua=mailto:dmarc@<domain>" then move to quarantine/reject
LOWCAA_MISSING-@CAAno CAA record: any public CA may issue certificates for this domainoptional hardening: CAA 0 issue "<your CA>" limits who may issue certificates

Out-of-zone targets to check live (no network calls were made)

TargetUsed by
bakery-site.example.net.@ CNAME (line 14); www CNAME (line 15)
mx2.example.net.backupmx CNAME (line 26)
ns1.example.net.@ NS (line 10)
ns2.example.net.@ NS (line 11)
shops.myshopify.com.shop CNAME (line 17)

FILE:scripts/dns_lint.py #!/usr/bin/env python3 """DNS zone record linter (Python 3.8+ standard library only, works offline).

Reads a BIND-style zone file or a CSV record list exported from a DNS provider and reports common mistakes before they break web or mail delivery: CNAME at the apex or next to other records, MX/NS pointing at a CNAME or an IP, missing trailing dots (mail.example.com -> mail.example.com.example.com.), missing or duplicate SPF, SPF syntax, +all/?all and the 10-lookup limit, DMARC and DKIM presence and syntax, weak or revoked DKIM keys, TTL extremes, private addresses in a public zone, SOA mistakes, duplicate records, and domains that send no mail but have no "no mail" policy. Out-of-zone targets are listed for a separate live check.

Usage: python3 dns_lint.py example.com.zone [--origin example.com] [--json] [--min-severity LOW|MEDIUM|HIGH] [--ignore CODE,CODE] python3 dns_lint.py records.csv --origin example.com (CSV columns: name,type,value[,ttl][,priority]) python3 dns_lint.py --self-test Zone files: $ORIGIN, $TTL, @, relative names, blank owner (repeat previous), optional TTL/class in either order, ( ) multi-line records, ; comments, quoted TXT strings. Exit codes: 0 = no HIGH findings, 1 = HIGH findings, 2 = bad input. """ import argparse, base64, csv, io, ipaddress, json, os, re, sys

SEVERITIES = ["LOW", "MEDIUM", "HIGH"] CLASSES = {"IN", "CH", "HS"} TYPES = {"A", "AAAA", "CNAME", "MX", "NS", "TXT", "SPF", "SOA", "SRV", "CAA", "PTR", "DNAME", "ALIAS", "ANAME", "DS", "DNSKEY", "RRSIG", "NSEC", "NSEC3", "NSEC3PARAM", "HTTPS", "SVCB", "TLSA", "NAPTR", "SSHFP", "LOC", "HINFO", "CDS", "CDNSKEY"} DNSSEC_TYPES = {"RRSIG", "NSEC", "NSEC3", "KEY"} TARGET_TYPES = {"CNAME": -1, "MX": 1, "NS": 0, "PTR": 0, "DNAME": 0, "SRV": 3, "ALIAS": 0, "ANAME": 0} COMMON_TLDS = set("com net org edu gov mil int io co dev app ai info biz me tv cloud xyz site online " "shop store tech us uk de fr nl eu es it se no dk fi pl cz at ch be pt ie tr ru " "jp cn kr in au nz ca br mx ar za sg hk tw".split()) INTERNAL_NETS = [ipaddress.ip_network(n) for n in ( "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10", "127.0.0.0/8", "169.254.0.0/16", "0.0.0.0/8", "::1/128", "::/128", "fc00::/7", "fe80::/10")] # documentation ranges (192.0.2.0/24, 2001:db8::/32) are allowed SPF_LOOKUP_TERMS = ("include", "a", "mx", "ptr", "exists", "redirect")

The text continues at the source. Read the rest.

Source: https://github.com/f/prompts.chat/blob/main/prompts/02760.md

Author: f, prompts.chat prompt library. License: CC0-1.0.

Shown here with formatting for the web; email addresses removed. Keep the author and license notice when you reuse it.

Related entries

There are more like this in the members library

The Business prompt library holds 3,008 entries. Members can search all of them by meaning and read every one in full.