CNAME flattening is a CDB Managed DNS feature that resolves CNAME chains at the zone apex to A or AAAA records, bypassing the RFC 1034 restriction that prevents CNAME records from coexisting with mandatory NS and SOA records.
Zone apex record restrictions
CNAME records are increasingly used to integrate domains with CDNs and other services that route traffic through dynamically assigned IP addresses. Using an A record, which specifies the concrete IP address that resolves the domain, may not be suitable in cases where IP addresses change frequently based on the geolocation of requests.
According to the RFC 1034 specification, a CNAME record cannot coexist with other records. Therefore, it is impossible to specify a CNAME record for the root domain, also known as the "apex domain" (e.g., sample-test.com), because it has mandatory NS and SOA records.
While using a subdomain (e.g., cdn.sample-test.com) for CNAME record creation can be sufficient, some website owners may want to integrate their root domain. For this situation, CDB Managed DNS provides the CNAME flattening feature.
CNAME flattening mechanism
CNAME flattening is a mechanism that allows specification restrictions to be bypassed, enabling a CNAME to be specified for the root domain. It resolves the CNAME chain and uses the IP address of the final A or AAAA record. This synthetic record is then cached, respecting its TTL, and used to answer subsequent DNS queries for the apex domain on the CDB DNS side.
The local cache layer can also reduce resolution time by serving subsequent queries from the cached flattened response.
Configuration of CNAME flattening
CDB Managed DNS provides CNAME flattening to customers on all plans by default.
1
Navigate to the Records tab
In the CDB Technical Web Portal, navigate to DNS → Managed DNS, click the zone name, and open the Records tab.
2
Remove conflicting records
Delete the A record and any other record types at the zone apex that would conflict with the CNAME record. Click the delete icon next to each conflicting record and confirm the deletion.
NS and SOA records are mandatory and must remain — CNAME flattening exists precisely to handle their coexistence with the CNAME.
3
Add a CNAME record
Click Add record and configure the new record:
Set Type to CNAME.
In the Name field, enter the root domain.
In the Content field, enter the target domain.
Click Add.
CDB Managed DNS supports CNAME flattening only when the zone apex contains a single CNAME record. The CDB DNS Lookup tool verifies the resolved value of the apex domain.
CNAME flattening at the zone apex requires two sequential API calls: delete all conflicting RRsets at the apex, then create the CNAME record. The zone apex record name equals the zone name.
📝
All conflicting RRsets must be deleted before the CNAME is created. NS and SOA records are mandatory and must remain. Creating a CNAME while any other record type exists at the apex returns HTTP 409: "cname can't coexists with other records".
Open a terminal and export the required variables:
export GCORE_API_KEY="{YOUR_API_KEY}"
export ZONE_NAME="{YOUR_ZONE_NAME}" # e.g. example.com
export CNAME_TARGET="{YOUR_CNAME_TARGET}" # e.g. cdn.example.com
Configure CNAME flattening
Declare a CNAME at the zone apex using gcore_dns_zone_rrset from the CDB Terraform provider v2. The rrset_name must equal the zone name. CDB DNS resolves the CNAME chain to A or AAAA records and serves the flattened result to clients.
📝
A CNAME cannot coexist with any other record type at the apex (except the mandatory NS and SOA). Declaring both gcore_dns_zone_rrset resources with rrset_type = "CNAME" and rrset_type = "A" for the same apex in one configuration fails with 409 Conflict. Remove or comment out other apex records before adding the CNAME.
Configure CNAME flattening
On a fresh zone (or after removing conflicting apex records), declare the CNAME resource. The rrset_name equals the zone name — that is the apex.
resource "gcore_dns_zone" "example" {
name = "yourdomain.com"
}
resource "gcore_dns_zone_rrset" "apex_cname" {
zone_name = gcore_dns_zone.example.name
rrset_name = gcore_dns_zone.example.name # apex — same as zone name
rrset_type = "CNAME"
ttl = 300
resource_records = [
{ content = ["cdn.yourdomain.com"] }, # CDN delivery domain or other target
]
# terraform import gcore_dns_zone_rrset.apex_cname yourdomain.com/yourdomain.com/CNAME
}
The provider returns an RFC 1034 advisory warning about CNAME coexisting with NS and SOA records. The warning is expected — CDB Managed DNS handles the flattening transparently and the record is created successfully.
To update the CNAME target, change content and run terraform apply. Terraform updates the record in place.
Revert to a standard record
To replace the CNAME with an A or AAAA record, remove the apex_cname resource block and declare a new resource with the desired type. Terraform deletes the CNAME first, then creates the A record — the order is handled automatically, so the 409 conflict does not occur.