Skip to content
TPOALOSPublic

About

Offline lint of BIND DNS zone files: SOA/NS sanity, CNAME conflicts, SPF/DMARC/CAA, takeover-prone targets (stdlib-only Python)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

zonelint

Find the DNS zone-file mistakes that break mail, hide outages or invite subdomain takeover, without touching the network. A BIND zone file is easy to get subtly wrong: a CNAME at the apex, an MX that points at a CNAME, a missing trailing dot that turns host.example.com into host.example.com.example.com., a second SPF record, a CNAME left pointing at a deleted cloud app. zonelint parses the file and reports these. It never performs a DNS lookup, never opens a socket and never follows $INCLUDE.

Real output on a small synthetic zone (--min-severity medium; the full run also lists 3 low and 4 info findings):

$ zonelint z1.zone --min-severity medium
z1.zone (zone example.com., 17 records)
  HIGH   ZL120 line 7   CNAME at the zone apex conflicts with SOA/NS (use ALIAS/ANAME at your provider or an A record)
  HIGH   ZL121 line 8   www.example.com. has a CNAME and also A records; a CNAME must be the only record at its name
  HIGH   ZL130 line 12  MX target 192.0.2.9 is an IP address; it must be a host name
  HIGH   ZL140 line 13  NS target www.example.com. is a CNAME in this zone; NS must point at an address-bearing host
  HIGH   ZL171 line 19  more than one SPF record at the apex; receivers return permerror, so SPF fails
  HIGH   ZL172 line 19  SPF ends in +all, which authorizes every sender on the internet
  MEDIUM ZL103 line 3   SOA RNAME uses '@'; write the mailbox with a dot instead (hostmaster.example.com.)
  MEDIUM ZL210 line 9   A record points at a private (RFC1918) address (10.0.0.5); not reachable from the public internet
  MEDIUM ZL130 line 11  MX target mail.example.com. is a CNAME in this zone; MX must point at an address-bearing host
  MEDIUM ZL210 line 15  A record points at a private (RFC1918) address (192.168.1.10); not reachable from the public internet
  MEDIUM ZL200 line 17  CNAME target host.example.com has no trailing dot and looks fully qualified; it expands to host.example.com.example.com.
  MEDIUM ZL190 line 21  record type ANY is a query type and cannot appear in a zone file
  summary: 6 high, 6 medium, 0 low, 0 info
$ echo $?
1

The informational findings include the takeover-prone check, for example: INFO ZL180 line 8 CNAME to shop.herokuapp.com.: provider hostnames can be claimed by others when the resource is deleted; verify the target still exists.

One file, standard library only, Python 3.9+.

Usage

zonelint FILE [FILE ...] [--origin NAME] [--json] [--fail-on SEV] [--min-severity SEV]
                         [--allow-private] [--min-ttl N] [--max-ttl N] [--max-bytes N]
  • FILE is a zone file, or - for stdin. Use --origin example.com. when the file has no $ORIGIN.
  • --json prints machine-readable results (zone, records, summary, and findings with rule, name, severity, line, message).
  • --fail-on is the lowest severity that makes the exit code 1 (default low; info-only output is clean).
  • --allow-private silences the private-address rule for internal zones. TTL limits default to 60 and 604800 seconds.
  • Read-only. Symlinks, non-regular files, binary data and bad UTF-8 are refused with exit 2.

Rules

Rule Severity What
ZL100 / ZL101 high no SOA / more than one SOA
ZL102-ZL106 medium / info malformed SOA, @ in RNAME, bad or zero serial, serial not YYYYMMDDnn (info), expire shorter than refresh+retry
ZL110 / ZL111 high / medium no NS at the apex / fewer than two
ZL120 / ZL121 / ZL122 high CNAME at the apex / CNAME beside other records / several CNAMEs at one name (DNSSEC record types are allowed beside a CNAME)
ZL130 high or medium MX target is an IP address (high) or a CNAME in the zone (medium)
ZL140 high NS target is a CNAME in the zone or an IP address
ZL150 info wildcard record
ZL160 / ZL161 / ZL162 low / low / info TTL very low / very high / no TTL in effect
ZL170-ZL172 info or low / high / high no SPF (low when the apex has MX) / more than one SPF / SPF ending +all
ZL173 / ZL174 info or low / medium no DMARC at _dmarc / more than one
ZL180 info CNAME into a takeover-prone provider suffix (heroku, github.io, azurewebsites, s3 website, cloudfront, netlify...): verify the target still exists
ZL190 medium ANY/AXFR-style query type used as a record type
ZL191 / ZL192 low / info unrecognized record type / non-IN class
ZL200 medium name without trailing dot that looks absolute (already contains the zone name, or looks like a.b.com)
ZL210 / ZL211 medium private, loopback, link-local, CGNAT or ULA address in A/AAAA / invalid address
ZL220 info no CAA at the apex
ZL240 medium owner name outside the zone
ZL250 medium TXT string longer than 255 bytes
ZL900 / ZL901 medium / info syntax problem (unbalanced parentheses, unterminated quote, bad $TTL) / $INCLUDE, $GENERATE not processed

Exit codes: 0 clean, 1 findings at or above --fail-on, 2 usage or input error.

Limits

  • Offline by design: it cannot tell whether a CNAME target still exists, whether a nameserver answers, or whether glue is right. ZL180 is only a reminder to check.
  • $INCLUDE is not followed and $GENERATE is not expanded, so records they would provide are not linted. Only a single zone per file is assumed; delegations (NS below the apex) are not modelled and glue is not checked.
  • ZL200 is a heuristic and can flag a legitimate relative name that happens to end in a zone-like label.
  • Wildcard, MX and CNAME checks look at records in this file only. DNSSEC records are parsed as opaque text and not validated.
  • Presentation-format escapes (\DDD) are kept as text, not decoded. Extremely unusual BIND syntax may be reported as a syntax problem.
  • SPF is checked only for presence, duplicates and +all; includes, lookup counts and syntax are not evaluated. DMARC policy strength is not judged.
  • Tested with synthetic zones only.

More tools by TPOALOS: planguard · iamlint · apispec-lint · all 61 tools

About

Offline lint of BIND DNS zone files: SOA/NS sanity, CNAME conflicts, SPF/DMARC/CAA, takeover-prone targets (stdlib-only Python)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages