A TXT record (short for text record) is a type of resource record in the Domain Name System (DNS) used to provide the ability to associate arbitrary text with a host or other name, such as human readable information about a server, network, data center, or other accounting information.[1]
It is also often used in a more structured fashion to record small amounts of machine-readable data into the DNS.
A domain may have multiple TXT records associated with it, provided the DNS server implementation supports this.[2] Each record can in turn have one or more character strings.[3] Traditionally these text fields were used for a variety of non-standardised uses, such as a full company or organisation name, or the address of a host.
Some examples of TXT usage:
Using TXT records to store data for different purposes is not without problems. The DNS protocol specifies that when a client queries for a specific record type (e.g., TXT) for a certain domain name (e.g., example.com), all records of that type must be returned in the same DNS message. That may lead to large transactions with lots of "unnecessary" information being transferred and/or uncertainty about which TXT record to use. There are two ways around this: to specify a domain name prefix to be used when using TXT records for a specific purpose (e.g., _domainkey.example.com – in the DKIM case) or to create a new record type entirely. The former is "easy" because it doesn't require any changes to the DNS. The latter is sometimes considered "cleaner" as it matches the design of the DNS database model better. In the past, creating new record types was often avoided since it was a complicated procedure in the IETF. The reluctance lingers with some people despite the process having been replaced by a much lighter and quicker one.
The structure of the TXT record is specified in [10] as follows. Note that the specification is silent on the subject of character encoding of the text string. It explicitly states that the interpretation of the string is context dependent, and that the data is treated as binary inside the DNS. Later specifications (e.g., [11] – DNS used for service discovery) may require the use of specific encodings for specific purposes.
The RDATA section may contain multiple consecutive occurrences of (TXT Length + TXT). Data Length is the length of them all combined.
Name | Label Sequence | The domain name, encoded as a sequence of labels. | |
Type | 2-byte Integer | The record type. In this case will be as the Type is TXT. | |
Class | 2-byte Integer | The class. | |
TTL | 4-byte Integer | Time-To-Live, i.e. how long a record can be cached before it should be requeried. | |
Data Length | 2-byte Integer | Length of the record type-specific data. | |
TXT Length | 1-byte Integer | Length of TXT string. | |
TXT | String | The character-string. |
As part of this response, there are two text records, the first of which is shown below (beginning at byte 54).
This decodes as follows:
Name | example.com (This is a jump directive to an earlier label) | ||
Type | 0x0010 | TXT | |
Class | IN | ||
TTL | 21599 (5 hours, 59 minutes, 59 seconds) | ||
0x000c | 12 | ||
TXT Length | 11 | ||
TXT | v=spf1 -all |
As unstructured text, organisations can use the TXT string in any way they define, for example:
defines a structured format that can be used to define attributes and their values in a single record,[2] as in these examples:
In practice, services using TXT records often do not follow this RFC, but instead have their own specific format.[12] [13]
The character string from a TXT record used for SPF: "v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 ip6:2620:0:860::/46 a -all"An example of use for DMARC:
default._bimi TXT "v=BIMI1; l=https://example.com/image.svg; a=https://example.com/image/certificate.pem"