TXT record explained

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.

Background

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.

Format

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.

Record Structure!Field!Type!Description
NameLabel SequenceThe domain name, encoded as a sequence of labels.
Type2-byte IntegerThe record type. In this case will be as the Type is TXT.
Class2-byte IntegerThe class.
TTL4-byte IntegerTime-To-Live, i.e. how long a record can be cached before it should be requeried.
Data Length2-byte IntegerLength of the record type-specific data.
TXT Length1-byte IntegerLength of TXT string.
TXTStringThe character-string.
This is the hex returned as part of the DNS response from example.com when queried for TXT records.

0000 34 48 81 a0 00 01 00 02 00 00 00 01 07 65 78 610010 6d 70 6c 65 03 63 6f 6d 00 00 10 00 01 c0 0c 000020 10 00 01 00 00 54 5f 00 0c 0b 76 3d 73 70 66 310030 20 2d 61 6c 6c c0 0c 00 10 00 01 00 00 54 5f 000040 21 20 38 6a 35 6e 66 71 6c 64 32 30 7a 70 63 790050 72 38 78 6a 77 30 79 64 63 66 71 39 72 6b 38 680060 67 6d 00 00 29 02 00 00 00 00 00 00 00

As part of this response, there are two text records, the first of which is shown below (beginning at byte 54).0000 c0 0c 00 10 00 01 00 00 54 5f 00 0c 0b 76 3d 730010 70 66 31 20 2d 61 6c 6c

This decodes as follows:

Record Structure!Field!Hex!Value
Nameexample.com (This is a jump directive to an earlier label)
Type0x0010TXT
ClassIN
TTL21599 (5 hours, 59 minutes, 59 seconds)
0x000c12
TXT Length11
TXTv=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]

Example usage

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:"v=DMARC1;p=none;sp=quarantine;pct=100;rua=mailto:dmarcreports@example.com;"Use for site verification:"google-site-verification=6P08Ow5E-8Q0m6vQ7FMAqAYIDprkVV8fUf_7hZ4Qvc8"Use for custom email service:_amazonses.example.com. IN TXT "pmBGN/7MjnfhTKUZ06Enqq1PeGUaOkw8lGhcfwefcHU="Brand Indicators for Message Identification (BIMI):

default._bimi TXT "v=BIMI1; l=https://example.com/image.svg; a=https://example.com/image/certificate.pem"

See also

Notes and References

  1. RFC 1464 Using the Domain Name System To Store Arbitrary String Attributes. 1464. Rich Rosenbaum. May 1993. 2016-02-05. IETF.
  2. Web site: Using the Domain Name System To Store Arbitrary String Attributes. R.. Rosenbaum. Tools.ietf.org. 14 October 2018.
  3. 3.3.14 . TXT RDATA format . Domain names - implementation and specification . 1035 . November 1987 . P. Mockapetris . IETF.
  4. Web site: Verify your site ownership . 18 December 2018.
  5. Web site: Domain Verification . Facebook . 18 December 2018.
  6. Sender Policy Framework (SPF) for Authorizing Use of Domains in Email, Version 1 . 7208 . DNS Resource Records . 3.1 . Scott Kitterman . April 2014 . . 2014-04-26 .
  7. Web site: About TXT records. Google Apps Administration. 2014-08-17.
  8. 6762 . February 2013 . S. Cheshire and M. Krochmal, Apple Inc. . Multicast DNS . IETF.
  9. 6763 . February 2013 . S. Cheshire and M. Krochmal, Apple Inc. . DNS-Based Service Discovery . IETF.
  10. Web site: rfc1035. 2021-08-15. datatracker.ietf.org.
  11. Web site: rfc6763. 2021-08-15. datatracker.ietf.org. en.
  12. Web site: DNS Record Verification . WebNots . 21 December 2018.
  13. Web site: Amazon SES Domain Verification TXT Records . Amazon . 21 December 2018.