BIND is giving you an "unbalanced quotes near" error in your zone file because it’s finding a quotation mark that doesn’t have a corresponding closing quotation mark on the same line, or it’s finding a closing quote without an opening one. This is a syntax error that prevents BIND from parsing your zone file correctly.

Here are the common causes and how to fix them:

Mismatched Quotes in TXT Records

This is by far the most common culprit. TXT records often contain long strings, and it’s easy to miss a closing quote.

Diagnosis: Carefully examine every TXT record in your zone file. Look for lines that start with a quoted string and don’t end with one, or have an extra quote within the string.

Example of a bad TXT record:

yourdomain.com.  IN  TXT  "This is a test record with an unbalanced quote.

Fix: Ensure every opening quote has a matching closing quote on the same line.

yourdomain.com.  IN  TXT  "This is a test record with an unbalanced quote."

Why it works: BIND expects quoted strings to be properly terminated. An unbalanced quote signifies an incomplete string literal, causing a parsing failure.

Unbalanced Quotes in SRV Records

SRV records have a specific format and can also suffer from unbalanced quotes, especially within the target hostname.

Diagnosis: Inspect your SRV records. Pay close attention to the target part of the record, which is often a hostname that might be enclosed in quotes.

Example of a bad SRV record:

_sip._tcp.yourdomain.com.  IN  SRV  10 60 5060 "sipserver.yourdomain.com

Fix: Ensure the target hostname within the SRV record is correctly quoted.

_sip._tcp.yourdomain.com.  IN  SRV  10 60 5060 "sipserver.yourdomain.com."

Why it works: Similar to TXT records, the SRV record’s target field is treated as a string literal by the parser. Proper quoting is essential for its interpretation.

Unbalanced Quotes in Comments

While less common, an unbalanced quote within a comment can still trip up the parser if the comment is not properly terminated or if the quote is interpreted as part of the record data.

Diagnosis: Look for lines that start with a semicolon (;) for comments. If you have quoted text within a comment, ensure it’s balanced.

Example of a bad comment:

; This is a comment with an "unbalanced quote
yourdomain.com.  IN  A  192.168.1.1

Fix: Ensure any quotes within comments are also balanced.

; This is a comment with an "unbalanced quote".
yourdomain.com.  IN  A  192.168.1.1

Why it works: Although comments are ignored by the DNS resolver, the BIND zone file parser still processes the entire line for syntax errors. If a quote appears in a context where the parser expects a record element, it can cause issues.

Missing Parentheses in Longer Records

Sometimes, what appears as an "unbalanced quotes" error is actually a sign of a missing closing parenthesis ) on a line where multiple DNS records are combined, or where a long string is split across multiple lines using parentheses.

Diagnosis: Check for lines that span multiple lines using parentheses. Ensure each opening parenthesis has a corresponding closing parenthesis.

Example of a bad record spanning multiple lines:

yourdomain.com.  IN  TXT  ("This is a very long string that needs to be split across "
                           "multiple lines, but one parenthesis is missing.)

Fix: Add the missing closing parenthesis.

yourdomain.com.  IN  TXT  ("This is a very long string that needs to be split across "
                           "multiple lines, but one parenthesis is missing.")

Why it works: BIND uses parentheses to group text strings that span multiple lines. A missing parenthesis breaks this grouping mechanism, leading the parser to incorrectly interpret the end of the string and potentially reporting quote errors.

Accidental Quotes in Hostnames or IPs

It’s easy to accidentally add a quote around a hostname or IP address where it doesn’t belong.

Diagnosis: Scan your zone file for any hostnames or IP addresses that are unexpectedly enclosed in quotation marks.

Example of a bad A record:

server.yourdomain.com.  IN  A  "192.168.1.10"

Fix: Remove the erroneous quotes.

server.yourdomain.com.  IN  A  192.168.1.10

Why it works: IP addresses and hostnames in DNS records are not typically enclosed in quotes unless they are part of a larger string literal (like in TXT or SRV records). Unquoted hostnames and IPs are the standard format.

Tooling and Best Practices

  • named-checkzone: Always use named-checkzone to validate your zone files before reloading BIND.

    named-checkzone yourdomain.com /etc/bind/db.yourdomain.com
    

    This command is invaluable for catching syntax errors.

  • Text Editors with Syntax Highlighting: Use a text editor that supports BIND zone file syntax highlighting. This can visually help you spot mismatched quotes or other syntax issues.

  • Code Review: Have a colleague review your zone files, especially after making significant changes. A fresh pair of eyes can often catch errors that you might overlook.

After fixing all unbalanced quote errors, the next error you’ll likely encounter is a "missing semicolon" if you’ve introduced other syntax issues while correcting the quotes.

Want structured learning?

Take the full Dns course →