Whether building a website, configuring email, or linking a CDN, we all encounter domain name resolution. The core of domain name resolution is DNS, which is responsible for converting human-friendly domain names into computer-readable IP addresses. However, when we open the domain name resolution panel, we often see a long list of resolution types: A, CNAME, MX, TXT, AAAA, NS, SRV, CAA, etc. Many people wonder: What do these types represent? Which one should I choose for my website? Can I set up multiple resolutions for the same domain name? This article will systematically explain the four most commonly used resolution types: A records, CNAME records, MX records, and TXT records, helping you truly understand their differences and usage.
Ⅰ. What is Domain Name Resolution (DNS Resolution)
Domain name resolution is the process of converting a domain name into a corresponding IP address. When a user enters a URL in a browser, the DNS system searches for the domain name's resolution record and tells the browser which server to access. For example: A user enters "www.example.com" and the DNS returns "192.168.1.1." The browser connects to the server and the website opens successfully.
The essence of DNS resolution is to allow users to access the real IP address of a website server through an easy-to-remember domain name. To achieve this, we need to add resolution records at our domain registrar or DNS service provider. Different types of records represent different purposes.
II. A Records
The A record is the most commonly used resolution type, used to point a domain name to an IPv4 address. It tells the DNS system, "This domain name corresponds to which server IP address."
Suppose your server IP address is 123.45.67.89. If you want users to access your site through www.example.com, you need to add the following A record. This way, when users visit www.example.com, they will automatically be redirected to the server at 123.45.67.89.
Applicable Scenarios: Website binding to a dedicated server or virtual host, CDN node back-to-origin configuration, cloud server access, and any business requiring direct access to the server IP.
Note: A records only support IPv4 addresses; IPv6 requires AAAA records. Multiple A records can be set for the same domain for load balancing (multiple IP addresses). If the server IP changes, the A record must be modified simultaneously; otherwise, access will fail.
III. CNAME Records
A CNAME record, also known as an "alias record," points one domain to another, automatically resolving it to the target domain's IP. In other words, an A record points to an IP address, while a CNAME record points to another domain.
If your primary domain is example.com and you've already set an A record to point to the server IP address, and you want www.example.com to also access the same website, you can use a CNAME. This way, accesses to www.example.com will automatically be redirected to example.com's IP address.
Applicable Scenarios: Redirecting from a secondary domain to the primary domain, using dynamic domain name binding assigned by CDN services, cloud storage, load balancing, and other services.
Note: You can't set both an A record and a CNAME record for the same hostname. A CNAME record can't be used for MX (email) or NS (name server) records. If the target domain pointed to by a CNAME is invalid, resolution will fail.
IV. MX Records
MX records are used to configure email servers, telling the DNS which server is responsible for receiving email for that domain. For example, when someone sends an email to admin@example.com, the DNS will look up the MX record for example.com and deliver the email to the corresponding server. If you have multiple email servers, you can set up multiple MX records, with different priorities representing backup (lower numbers indicate higher priorities).
Applicable scenarios: Configuring corporate email, Google Workspace, and Outlook; hosting your own email server; and connecting to email service providers (QQ Mail, NetEase Enterprise Mail, and Alibaba Cloud Mail).
Note: The MX record value must be a domain name, not an IP address. MX records are typically used in conjunction with an A or CNAME record to ensure that the email server address can be resolved properly.
Ⅴ. TXT Records
TXT records were originally designed to store arbitrary text information, but are now primarily used for authentication and security purposes. They can store various authentication tokens, such as email verification, website identity verification, and security policies.
Common Uses: Domain ownership verification (such as with Baidu and Google Webmaster Tools), email SPF/DKIM/DMARC anti-spam verification, third-party service authorization, and API/email signature verification.
Note: TXT content has a limited length (generally no more than 255 characters); multiple TXT records can be set for the same domain. TXT does not affect website access, but incorrect configuration may cause authentication failures.
VI. Summary of the Differences Between A, CNAME, MX, and TXT Records
A Records: Point to an IPv4 address, suitable for website access and server binding. They are the most basic and direct.
CNAME Records: Point to another domain name, commonly used for second-level domain redirection and CDN. They offer flexible binding, but cannot coexist with A Records.
MX Records: Point to a mail server, commonly used for domain mailbox configuration. They require a priority setting.
TXT Records: Point to arbitrary text content, suitable for authentication, SPF, and security policies. They don't affect access and are primarily used for authentication.
In short: "A" is the foundation, "CNAME" is an alias, "MX" is responsible for mailboxes, and "TXT" is used for authentication.
VII. FAQs
Q1: Can A and CNAME records be set simultaneously?
A1: No. Only one type of record can be set for the same hostname (e.g., www): either A or CNAME. Otherwise, conflicts will occur.
Q2: Does a TXT record affect website access speed?
A2: No. TXT records are only read for authentication and security policy purposes and are not involved in web page loading.
Q3: Why does the website still access the old server after I modified the A record?
A3: The DNS cache hasn't been refreshed. You can wait for the TTL (usually several minutes to several hours) or clear the local DNS cache.
Q4: Are email delivery failures related to MX records?
A4: Yes. An incorrect MX configuration or incorrect priority can prevent email delivery.
Q5: How can I determine if domain name resolution is working?
A5: You can test by using the ping or nslookup commands to see if the returned IP address matches your server.
Q6: Can I have multiple A records for a single domain?
A6: Yes. Multiple A records can be used for simple load balancing or multi-channel access.
Q7: Can TXT records contain Chinese characters?
A7: While UTF-8 encoding is theoretically supported, it's recommended to use only English, numbers, and symbols to avoid garbled characters or verification failures.
Domain name resolution may seem complex, but understanding the logic behind each record makes it easy to master. A. CNAME, MX, and TXT are the core foundations of DNS. They not only determine website accessibility, but also influence email delivery, verification, and security. Whether you're a webmaster, maintenance engineer, or just starting out on your own website, mastering these DNS basics will greatly enhance your website management experience. Remember: "A correct domain name resolution ensures a smooth website operation."