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
- 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 (). - 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.
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:
TEXT
default._domainkey.example.com. 3600 IN TXT v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3...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
STATE_STANDARD, STATE_IN_STRING, STATE_ESCAPE, and STATE_COMMENT.
TEXT
[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)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:
TEXT
default._domainkey.example.com. IN TXT ( v=DKIM1; k=rsa;
p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3...
) ; closing record- It reads the open parenthesis
(and increments its grouping nesting counter from0to1. - It reads
v=DKIM1as an unquoted character string token. - It hits the first semicolon
;while still outside double quotes. The lexer switches toSTATE_COMMENT. - It ignores
k=rsa;and flushes everything up to the newline. - The next line begins with
p=MIGf.... Because the grouping counter is still1, the lexer treats this as an additional, unquoted token for the same TXT record. - 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.
- 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 to0. The parser reaches the end of the file (EOF) with an open parenthesis and throwsunexpected end of file.
Daemon Failure Modes: Reload vs. Clean Cutover
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) orREFUSED(RCODE 5).
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
1. Enclosing in Double Quotes (Standard)
STATE_IN_STRING and treats the semicolon as a literal ASCII 0x3B byte.
TEXT
; Valid: Quoted strings preserve semicolons
_dmarc.example.com. 3600 IN TXT "v=DMARC1; p=reject; rua=mailto:[email protected]"2. Backslash Escaping (Unquoted Strings)
\). The lexer encounters the escape character, transitions to STATE_ESCAPE, and consumes the semicolon as a literal character rather than a comment trigger.
TEXT
; Valid: Backslash prevents the lexer from switching to comment state
_dmarc.example.com. 3600 IN TXT v=DMARC1\; p=reject\; rua=mailto:[email protected]3. Splitting Strings Over 255 Octets
<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:
TEXT
; 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;"
)Pre-Flight Syntax Verification
named-checkzone:
BASH
named-checkzone example.com /etc/bind/zones/example.com.zoneTEXT
/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 errorsnsd-checkzone:
BASH
nsd-checkzone example.com /etc/nsd/example.com.zonepdnsutil check-zone:
BASH
pdnsutil check-zone example.com0 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.