Is a wildcard CNAME DNS record valid?

Better Stack Team
Updated on November 23, 2023

In the Domain Name System (DNS), a CNAME (Canonical Name) record is used to create an alias from one domain name to another. A wildcard DNS record is a record that matches requests for non-existent subdomains. However, a wildcard CNAME record, while logically appealing, is not a valid DNS configuration due to technical restrictions.

The reason behind this is rooted in how DNS works and the limitations imposed by the standards governing DNS. According to the DNS standards, it's not allowed to have a CNAME record coexist with other records for the same domain.

A wildcard DNS record is specified with an asterisk (*) and is typically used for catching requests for all undefined subdomains of a domain and directing them to a specific location or IP address. For example, if you create a wildcard record for *.example.com, all undefined subdomains like subdomain1.example.com, subdomain2.example.com, etc., will resolve to the defined location.

The problem arises when you attempt to create a wildcard CNAME record (e.g., *.example.com pointing to someotherdomain.com). This configuration is not allowed by DNS standards because other resource records like NS, SOA, or other specific records should coexist with CNAME records.

The presence of a CNAME record effectively redirects all queries for that specific domain or subdomain. When using a wildcard CNAME, it creates potential conflicts with other DNS records that are essential for the functioning of that domain or subdomains. This conflict can disrupt the DNS resolution process and lead to unpredictable behavior or even failure in DNS lookups.

To maintain a properly functioning DNS structure and adhere to standards, it's recommended not to use wildcard CNAME records. If you need a wildcard DNS configuration, consider using other record types compatible with wildcard entries, such as A (IPv4 address), AAAA (IPv6 address), or other types of records that can be used as a wildcard.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github