All ArticlesDNS2026-11-10T17:49:41+08:00

Zone Fails to Load After DNS Migration? Check for Unescaped Semicolons in TXT

Importing legacy zone files into modern nameservers can cause silent drops or syntax errors when semicolons in TXT records are unescaped. You will learn how modern zone parsers interpret semicolons and how to escape them safely before cutover.

A DNS migration seems complete right up until authoritative nameservers stop resolving the entire domain. Zone transfers appear healthy in the export script, but the destination nameserver returns SERVFAIL or REFUSED on every query immediately after cutover. In production hosting environments, this failure rarely stems from network routing or firewall rules. The daemon usually failed to compile the zone file on boot because a semicolon in a TXT record was parsed as the start of a comment.

Semicolons are fundamental to email authentication records. DomainKeys Identified Mail (DKIM) separates tags with semicolons (v=DKIM1; k=rsa; p=...), and Domain-based Message Authentication, Reporting, and Conformance (DMARC) relies on the same delimiter (v=DMARC1; p=reject; rua=...). When exporting these records from modern web control panels or managed cloud DNS providers into raw RFC 1035 master zone files, quotation marks are frequently stripped or mismanaged. To an authoritative DNS daemon, a bare semicolon changes how the entire line is tokenized.

The RFC 1035 Semicolon Trap

Standard DNS master file format is defined in RFC 1035 Section 5.1. The specification establishes two rules that collide directly during migrations:

  1. Semicolons denote comments: Any unquoted and unescaped semicolon (;) instructs the parser to ignore all remaining characters on that physical line up to the line feed ( ).
  2. TXT records store one or more <character-string> elements, where strings containing whitespace or special delimiter characters must be enclosed in double quotes or escaped with backslashes.

When a zone is managed through an API or a modern web UI, the interface abstracts these rules. The database stores the raw string value v=DKIM1; k=rsa; p=MIGfMA0... in a database column. However, when an export routine or an automated migration script writes that record into a BIND-compatible flat file, it must serialize the data into master file syntax.

If the export script outputs the record without quotes:

default._domainkey.example.com.  3600  IN  TXT  v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3...

The parser does not see a valid DKIM policy. It reads v=DKIM1 as the data payload, encounters the unescaped ;, treats k=rsa; p=... as human commentary, and discards the rest of the line. At best, the nameserver publishes a corrupt TXT record containing only v=DKIM1, breaking email signing. At worst, the record is nested inside multiline parentheses, causing the parser to crash or discard the zone entirely.

Lexical Tokenization: How Zone Parsers Fail

To understand why a single character can bring down a zone, consider how nameserver daemons like BIND 9, NSD, or Knot DNS read zone files. Daemons do not treat zone files as arbitrary text blocks; they feed them through a lexical analyzer (lexer) and a parser (typically constructed with tools like Lex and Yacc/Bison).

The lexer processes an incoming stream of characters and categorizes them into tokens based on internal state transitions. When reading a resource record, the lexer operates roughly in four states: STATE_STANDARD, STATE_IN_STRING, STATE_ESCAPE, and STATE_COMMENT.

[Character Stream] ---> (Lexer State Machine)
                            |
       +--------------------+--------------------+
       |                    |                    |
[Char: "]               [Char: \]            [Char: ;]
       |                    |                    |
       v                    v                    v
Toggle State:        Enter State:         If NOT in String:
STATE_IN_STRING      STATE_ESCAPE         Enter STATE_COMMENT
(Consume until ")    (Literal next char)  (Discard to EOL)

When the parser is in STATE_STANDARD (outside quotes) and reads a semicolon, it immediately transitions to STATE_COMMENT. In this state, the lexer discards every byte until it encounters a newline character ( ), at which point it returns to STATE_STANDARD.

Trouble escalates when administrators split long records—such as 2048-bit DKIM keys—across multiple lines using grouping parentheses ( ... ). In RFC 1035 syntax, parentheses allow resource record data to span multiple lines by temporarily suspending newline-based record termination. Consider this common export formatting error:

default._domainkey.example.com.  IN  TXT  ( v=DKIM1; k=rsa;
                                            p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3...
                                            ) ; closing record

Because the initial string lacks enclosing quotation marks, the lexer processes the record as follows:

  1. It reads the open parenthesis ( and increments its grouping nesting counter from 0 to 1.
  2. It reads v=DKIM1 as an unquoted character string token.
  3. It hits the first semicolon ; while still outside double quotes. The lexer switches to STATE_COMMENT.
  4. It ignores k=rsa; and flushes everything up to the newline.
  5. The next line begins with p=MIGf.... Because the grouping counter is still 1, the lexer treats this as an additional, unquoted token for the same TXT record.
  6. The parser attempts to validate the record against RR type specifications. In many daemon implementations, consecutive unquoted tokens that do not conform to standard delimited strings cause a semantic parse error.
  7. If an unquoted semicolon appears on the same line right before the closing parenthesis ), the lexer discards the parenthesis as part of the comment. The grouping nesting counter never returns to 0. The parser reaches the end of the file (EOF) with an open parenthesis and throws unexpected end of file.

When a core zone file contains syntax errors of this magnitude, the nameserver daemon aborts zone compilation. In large infrastructure environments, unexpected parsing behavior in core records can trigger nameserver daemon panics, as detailed in the analysis of the Cloudflare Outage: What It Means for Your Cloud Infrastructure, where zone file parsing errors caused widespread service degradation.

Daemon Failure Modes: Reload vs. Clean Cutover

The impact of a parse failure depends heavily on whether you are reloading an existing nameserver or staging a new one during a migration.

When an administrator runs rndc reload on an active BIND 9 server, BIND compiles the modified zone file into memory before swapping pointers in the internal radix tree. If the lexer trips on an unescaped semicolon, BIND logs an error (zone example.com/IN: loading from master file failed: syntax error) and dumps the update. Crucially, BIND keeps the previous valid zone image in memory. Queries continue to be served using the old data.

A DNS migration has no safety net. During a migration, you provision new nameservers or import records into a fresh platform. Before updating the registrar, you must stage the records, as outlined in Pre-populating DNS Records on New Nameservers Before Registrar Cutover. If the target server tries to load the zone file for the first time with an unescaped semicolon:

  • The zone fails its initial compilation.
  • The daemon has no previous in-memory database to fall back on.
  • The zone state is marked as inactive, dead, or non-existent.
  • When you switch delegations at the registrar, recursive resolvers query the new authoritative servers and receive SERVFAIL (RCODE 2) or REFUSED (RCODE 5).

Resolvers interpret SERVFAIL as a temporary server failure, not an NXDOMAIN. They retry secondary and tertiary nameservers. If all assigned authoritative servers share the same broken zone file, the domain vanishes globally as soon as resolver TTL caches expire.

Validating and Escaping Semicolons Safely

To prevent silent load failures, semicolons inside TXT records must be secured using one of two methods: wrapping the content in double quotes or escaping every literal semicolon with a backslash.

1. Enclosing in Double Quotes (Standard)

RFC 1035 specifies that a semicolon inside a double-quoted string does not trigger a comment state change. The lexer stays in STATE_IN_STRING and treats the semicolon as a literal ASCII 0x3B byte.

; Valid: Quoted strings preserve semicolons
_dmarc.example.com.  3600  IN  TXT  "v=DMARC1; p=reject; rua=mailto:dmarc-reports@example.com"

Ensure that the DMARC record sits at the correct hostname label rather than the root apex, a common misstep detailed in Thinking DMARC Is Live Because the TXT Record Exists? Check It Sits at _dmarc.

2. Backslash Escaping (Unquoted Strings)

If your zone compilation tooling generates unquoted strings, every literal semicolon must be preceded by a backslash (\). The lexer encounters the escape character, transitions to STATE_ESCAPE, and consumes the semicolon as a literal character rather than a comment trigger.

; Valid: Backslash prevents the lexer from switching to comment state
_dmarc.example.com.  3600  IN  TXT  v=DMARC1\; p=reject\; rua=mailto:dmarc-reports@example.com

3. Splitting Strings Over 255 Octets

RFC 1035 limits any single <character-string> inside a TXT record to 255 octets. A 2048-bit DKIM public key typically spans 400 or more characters. To store this in a zone file, the value must be broken into multiple distinct quoted strings inside parentheses. Semicolons must be quoted inside their respective chunks:

; Valid: Multi-string TXT record with quoted semicolons and 255-byte segmentation
default._domainkey.example.com.  3600  IN  TXT  ( 
    "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Y1vJb2..."
    "...xyzF+9W8wIDAQAB;"
)

The receiving client or validator (such as an incoming mail server checking DKIM) concatenates the contiguous strings into a single buffer before evaluating the cryptographic signature.

Pre-Flight Syntax Verification

Never update registrar nameservers without running a strict zone validator on the generated zone files. Every major DNS implementation includes an offline parser that uses the exact same lexical rules as the live daemon.

For BIND installations, validate the zone with named-checkzone:

named-checkzone example.com /etc/bind/zones/example.com.zone

Sample output format when an unescaped semicolon truncates a record:

/etc/bind/zones/example.com.zone:18: syntax error
/etc/bind/zones/example.com.zone:18: unexpected end of line
zone example.com/IN: loading from master file /etc/bind/zones/example.com.zone failed: syntax error
zone example.com/IN: not loaded due to errors

If using NSD, run nsd-checkzone:

nsd-checkzone example.com /etc/nsd/example.com.zone

If using PowerDNS with a BIND backend, run pdnsutil check-zone:

pdnsutil check-zone example.com

If the validator returns anything other than an exit code of 0 and an explicit OK status, do not proceed with cutover. Inspect the flagged line number, locate the TXT or SPF record, and verify that quotation marks fully encapsulate all semicolons. Catching a lexer error in an offline terminal check takes seconds; resolving a globally distributed SERVFAIL outage after delegating nameservers takes hours of waiting for resolver negative cache TTLs to expire.