I have a DNS domain with 3 TXT records:
$ORIGIN example.com.
@ IN TXT "thing one veryveryveryveryveryverylong"
@ IN TXT "thing two veryveryveryveryveryverylong"
@ IN TXT "thing three veryveryveryveryveryverylong"
When I do a DNS query (dig example.com. txt
) the reply fits in a UDP packet because the payload is less than 512 bytes (resulting in a packet less than 576 bytes).
However I know that if the reply is long enough, it will be truncated and the DNS client will have to repeat the request using TCP, which has longer length limits.
How can I calculate whether or not I have exceeded the length limit without generating the DNS records and doing a query?
I assume that the formula is something like:
N: the number of TXT records on that label.
P: the number of bytes in all the TXT records.
S: the total number of text segments (TXT records can have multiple text segments per record)
UDP is required if N*a + P*b + S*c is more than 512
What are the values of a, b, and c?
(or am I going in the wrong direction?)
Best Answer
In practice, you should not be trying to pre-calculate the exact response size of your TXT records prior to implementing them. There are many variables in play, some of which you do not control. Most admins generalize based off the size of an existing TXT record response that they observe from their authoritative server and call it a day. Since the focus of your question is how to avoid generalizing, this answer is going to focus on why it is difficult to use precise calculations.
(This answer should not be taken as a statement for or against trying to stay inside of 512 bytes, it is a commentary on the approach used to do so.)
Can you write a program or script that will do all of this calculation for you? Sure. Is it a good use of time for the problem you're trying to solve? Probably not. Use an existing TXT record within the zone as your rough sizing guideline, and if growing over 512 bytes is a concern make sure you are familiar with any "include" functionality built into the relevant standard leveraging the TXT records. (SPF, etc.)