When verifying website ownership, setting up corporate email security policies, or configuring third-party services, you'll often encounter the message: "Please add a TXT record to your domain's DNS." For those unfamiliar with domain management, this might sound a bit technical, but don't worry, it's as simple as adding a note to your address book. A TXT record is essentially a piece of plain text information that you can attach to your domain. Other services (such as search engines or mail servers) can read this text to verify your identity or obtain configuration instructions. The entire process is usually completed in the control panel provided by your domain service provider; simply find the correct location, fill in a few boxes, and it's done in minutes.
To understand how to add one, you first need to understand what a TXT record is and why we need it. You can think of a domain's DNS system as a vast, distributed phone book. It not only records "which IP address corresponds to the domain" (A record) but also various other information for various purposes. A TXT record is one such entry used to store text information. Its most common uses are:
First, domain ownership verification. When you use Google Search Console, Baidu Webmaster Tools, or certain CDN services, they require you to add a unique string (e.g., `google-site-verification=xxxxxxxx`) to your domain to ensure you're not impersonating someone. Only the legitimate domain administrator can perform this operation.
Secondly, email security and spam prevention. This is a crucial application scenario for TXT records. By adding SPF, DKIM, and DMARC records, you can tell mail servers worldwide: "Which mail servers are authorized to send emails on behalf of my domain," "Whether my emails have been tampered with," and "What to do if emails fail inspection." This effectively prevents others from spoofing your domain to send phishing emails, greatly improving email delivery rates.
Regardless of the service provider, the core process of adding TXT records is the same, with only slight differences in interface layout and terminology. The entire process can be summarized in five steps: log in to the console, locate the DNS management zone, add a new record, fill in the information, and save and apply.
Step 1: Log in to your domain service provider's management backend. Log in using the account you registered when purchasing the domain. If you forget where you bought your domain, you can check the "registrar" information using a WHOIS lookup tool.
Step 2: Locate the domain management list and access the DNS settings. After logging in, you can usually find your domain in "My Products," "Domain List," or "Management Console." Click on the domain to enter the details management page and look for tabs named "DNS Resolution," "Domain Resolution," "Name Servers," "Advanced DNS," or similar. This is where you manage all your DNS records (A, CNAME, MX, TXT, etc.).
Step 3: Add a new TXT DNS record. On the DNS settings page, you will see an "Add Record" button. After clicking it, you need to select the record type. In the type drop-down menu, select "TXT."
Step 4: Fill in the details of the TXT record. This is the most crucial step; usually, you only need to fill in two or three fields:
1. Host/Name Record: This field determines which subdomain the TXT record applies to. If you want to add it for the root domain (such as `example.com`), you usually fill in `@` or leave it blank. If you want to add a record for a specific subdomain (e.g., `mail.example.com`), enter `mail` here. Some service providers may require you to enter the full hostname.
2. Record Value/Content/Text: Here you need to paste the entire text content provided by your service provider. This is the most error-prone area. Please copy it completely and accurately, including all quotation marks (if any), equal signs, and random strings. Avoid adding spaces before or after.
3. TTL (Time to Live): This value indicates how long other DNS servers cache this record. For initial setup or testing, it is recommended to set a shorter time (e.g., 600 seconds or 10 minutes) for faster results. After confirming everything is correct, you can change it to a longer time (e.g., 3600 seconds or 1 hour) to improve efficiency.
Step 5: Save and wait for it to take effect. Click the "Confirm" or "Save" button. DNS records take time to take effect globally; this process is called "DNS propagation," and usually takes anywhere from a few minutes to several hours. You can check if a record is active globally using online DNS lookup tools (such as the `dig`, `nslookup` commands, or the `whatsmydns.net` website).
To illustrate, let's look at a concrete example. Suppose you want to add a Google verification record for the root domain `example.com`. In the Alibaba Cloud console, you would fill in something like this:
Record Type: TXT
Host Record: `@`
Record Value: `google-site-verification=9fT4x7AabcDeFgHiJkLmNoPqRsTuVwXyZ1`
TTL: 600 seconds
After saving, this record means that when someone queries the TXT record for `example.com`, this verification code will be returned, along with other possible information.
Besides operating in the web console, if you are an advanced user or need automated deployment, you can also manage DNS records via API or command line. For example, you can add records programmatically using Cloudflare's API. Below is a sample code snippet demonstrating how to use the Linux `curl` command to call the Cloudflare API to add a TXT record. You need to replace `ZONE_ID`, `API_TOKEN`, `NAME` (your domain name), and `CONTENT` (TXT value):
curl -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{
"type": "TXT",
"name": "example.com",
"content": "v=spf1 include:_spf.example.com ~all",
"ttl": 600
}'
When adding TXT records, there are a few common pitfalls to be aware of:
Verifying the SPF record for the email: The value of the SPF record usually starts with `v=spf1`, followed by a series of mechanisms (such as `include`, `ip4`, `a`, etc.). A domain can only have one SPF record. If you need to add multiple origins, be sure to merge them into the same record's mechanism list, rather than creating multiple TXT records.
Splitting Long Records: Some TXT record values are particularly long (especially certain DKIM records). The DNS protocol stipulates that there are length limits for single string segments. If you encounter problems, your service provider's console or documentation will usually guide you on how to correctly split the string (usually by enclosing multiple parts in quotation marks).
Waiting Patiently for Effect: After adding or modifying, do not repeatedly delete and re-add because you cannot immediately find results. Give the system some time and check with online tools in multiple locations, as local DNS caching can affect your query results.
Once you successfully add and verify, this TXT record will work silently in the background, whether it's helping you prove ownership of your website or protecting every outgoing email; it's an indispensable part of building a secure and trustworthy online identity. The entire operation itself is not complicated; the key is carefulness: carefully read your service provider's requirements, accurately copy and paste the record value, understand the meaning of the host record, and then wait patiently.
CN
EN