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.
2. DNS Record Types
The most popular DNS record types are the following:
2.1. CNAME Record
Uses of CNAME records that are typical include:
- Giving distinct hostnames for particular network services (email or FTP) and referring those hostnames to the root domain
- Use a subdomain on the domain like drafts.baeldung.com, and utilize CNAME to point to the www.baeldung.com
- Registering the same domain name in many nations and directing the regional “.com” versions there
- Directing traffic from other websites owned by the same company to the main website
2.2. DNS Resolution Process
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.
2.3. CNAME Restrictions
CNAME records have the following restrictions:
- Because the root domain is the DNS Start of Authority (SOA), which needs to link to an IP address, a CNAME cannot be present there
- CNAME only points to another domain name, not an IP address
- Except for DNSSEC records (RRSIG and NSEC), a hostname in a CNAME record cannot have any additional resource entries of other types like MX, A, etc.
- CNAME can point to other CNAME records. However, doing so isn’t a good idea because it is ineffective
- A CNAME alias may never be the target of an MX or NS record
- Email-related domains might not have a CNAME record, which might cause problems with various mail servers.
3. How to Overcome CNAME 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 126.96.36.199. 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.