A TXT record (short for text record) is a type of resource record in DNS. It is used to store descriptive text for the domain name.
This type of record can be used to provide additional information about your domain, such as SPF records or verification codes.
It is also commonly used by email servers and other applications that need a way to store arbitrary pieces of text.
In this article, we will cover how to check txt record with the dig command in Linux.
- Understanding DNS TXT Records
- Purpose of DNS TXT records
- Example of Txt record
- Query DNS Txt Record with Dig command
- Tip of DNS txt record
Table of Contents
Understanding DNS TXT Record
The original RFC only indicates that ‘text strings’ go in the ‘value’ field of a TXT record. This could be any text that the domain owner wants to associate with their domain. The domain owner can add these TXT records in the domain setting website.
Purpose of DNS TXT record
There are two important uses for DNS TXT records.
- email spam-prevention This txt record will list all the servers that are authorized to send email messages from a domain. The email receiver can check if the send is legal or not by this.
- domain ownership verification Domain owners can prove they control this domain by adding a specific TXT record.
Example of TXT record in Linux
A DNS TXT record consists of a hostname, a time-to-live (TTL) value, the record class (usually IN for internet), the record type (TXT), and the text data enclosed in double quotes. The text data can contain any human-readable text or structured data depending on the specific purpose of the record.
The following is one of TXT records for the domain google.com.
google.com. 0 IN TXT "google-site-verification=TV9-DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ"
Hostname:Specifies the specific domain or subdomain associated with the TXT record. The root domain is represented by “@” while subdomains have their respective names (e.g., “www” for www.example.com).
TTL: Determines the time duration in seconds for which the record can be cached by DNS resolvers before fetching a fresh copy from the authoritative DNS server. It helps control the caching behavior of DNS information across the internet.
Record Class: Specifies the class of the record, with DNS TXT records typically set to “IN” (internet).
Record Type: Indicates the type of the record, with TXT records identified as “TXT”, signifying that it is a text record.
Text Data: Contains the actual information stored in the TXT record. It is enclosed in double quotes and can be plain text, structured data, or specific configuration details depending on the intended purpose of the record.
Check DNS TXT Record with Dig command in Linux
The easiest way to check TXT record in Linux is using dig command.
To check the DNS TXT record using the dig command in Linux, you can follow these steps:
Open a terminal on your Linux system.
Run the following command to check the TXT record:
dig TXT example.com
Replace “example.com” with the actual domain for which you want to retrieve the TXT record. This command queries the DNS server for the TXT record associated with the specified domain.
Review the output. The dig command will display the DNS response, including the TXT record(s) if they exist.
Look for the “TXT” section in the output, which contains the text data associated with the TXT record.
Note: If you want to specifically query the TXT record for a subdomain, you can include the subdomain as part of the domain parameter. For example, to check the TXT record for “subdomain.example.com”, you would run:
dig TXT subdomain.example.com
dig google.com txt
This command will return all the txt records for Google.com. From the answer section, we can see that there are 9 txt records for this domain google.com. The following are 2 of them.
;; ANSWER SECTION:
google.com. 0 IN TXT "docusign=1b0a6754-49b1-4db5-8540-d2c12664b289"
google.com. 0 IN TXT "google-site-verification=wD8N7i1JTNTkezJ49swvWW48f8_9xveREV4oB-0Hf5o"
By default, dig performs a lookup for an A record if no type argument is specified.
Query DNS TXT record in Linux with nslookup command
The nslookup command is a versatile tool for querying DNS information, including TXT records, in Linux. It provides a quick and straightforward way to retrieve specific DNS records and troubleshoot DNS configurations.
To query the DNS TXT record using the nslookup command in Linux, you can follow these steps:
Open a terminal on your Linux system.
Run the following command to start the nslookup utility:
This will launch the interactive mode of nslookup.
Set the query type to TXT by entering the following command:
Query the TXT record by entering the domain for which you want to retrieve the TXT record:
Replace “example.com” with the actual domain name you want to query.
Review the output. The nslookup command will display the DNS response, including the TXT record(s) if they exist. Look for the “TXT” section in the output, which contains the text data associated with the TXT record.
You can also use the following way.
For example, to query the TXT records for a domain, you would type “nslookup -type=txt example.com “. This will return a list of all of the TXT records for the domain.
If you want to see the reverse DNS record for a domain, you can type “nslookup -type=PTR ” followed by the IP address that you want to query. This will return a list of all of the domains that are hosted on the given IP address.