Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
A domain name is identified as the alias or nickname for another domain name via a canonical name (CNAME), a type of record in the Domain Name System (DNS) database. Further, the CNAME, sometimes known as the “real name,” is crucial when several services are performed from a single IP address.
In this tutorial, we’ll discuss various types of DNS records. Finally, we’ll discuss how to overcome root domain CNAME restrictions.
The most popular DNS record types are the following:
| Record | Description |
|---|---|
| A | Address for IPv4 |
| CNAME | Canonical Name |
| AAAA | Address for IPv6 |
| MX | Mail Exchanger |
| NS | Nameserver |
| PTR | Pointer |
| SOA | Start of Authority |
| SRV | Service location |
| TXT | Text |
Uses of CNAME records that are typical include:
Let’s discuss the DNS request resolution process using CNAME records with the help of an example:
Let’s consider the DNS client request for the address drafts.baeldung.com. The DNS resolver locates the Authoritative Name Server holding the DNS Zone file containing the necessary DNS records for the baeldung.com domain.
Furthermore, once the resolver receives the CNAME record, it comes to know that drafts.baeldung.com is an alias of the root domain baeldung.com. Next, the resolver gets the IP address of drafts.baeldung.com from the host and pass on to the client.
Finally, using the IP address, the client connects to drafts.baeldung.com.
CNAME records have the following restrictions:
To regulate, DNS uses a set of guidelines (RFC 1912 and RFC 2181). Further, these guidelines preclude a CNAME from being used on the root domain. This is because the root domain is the DNS SOA and must point to an IP address, not a canonical name.
For example, for drafts.baeldung.com, the CNAME will point to www.baeldung.com. But the root domain expects the IP address 45.79.199.121. Hence, the suggested guideline would be in conflict.
The fact is that this constraint is contractual rather than technical. Equally important, it is feasible to utilize a CNAME at the root. However, doing so may bring on unanticipated issues because it violates the intended code of conduct.
Let’s now try to find a solution to overcome the restrictions. What’s more, several DNS service providers have created unique techniques to get around this issue, including:
All of these virtual record types offer CNAME-like behaviors without any of the drawbacks.
Although the precise implementation may vary, when the DNS server encounters one of these virtual record types, it functions as a DNS resolver. It proceeds down the alias-created chain until it reaches an A record (or records), at which point it sends those A records back to the DNS server.
If your DNS provider does not offer a virtual record type and you don’t have one that does, then you may try subdomain redirection.
In this article, we talked about how to overcome root domain CNAME restrictions. It’s crucial to note that this limitation is contractual rather than technical. Although it is possible to use a CNAME at the root, this can produce unexpected problems since it violates the intended code of conduct.
Some virtual records types like CNAME (virtual), ALIAS, and ANAME offer CNAME-like behaviors to overcome root domain CNAME restrictions.