Introducing PostScale -- email API for transactional, inbound, and masked addresses. PostScale

    CNAME Records Explained

    Understand how CNAME records work, their limitations, and when to use them. Includes examples for the DNScale dashboard and API.

    A CNAME (Canonical Name) record creates an alias from one domain name to another. Instead of pointing to an IP address, a CNAME points to another domain name, which is then resolved to get the final IP address.

    How CNAME Records Work

    When a DNS resolver encounters a CNAME record, it follows the alias to find the actual IP address:

    blog.example.com.    3600    CNAME    example.com.
    example.com.         3600    A        192.0.2.1

    Query flow:

    1. Client asks for blog.example.com
    2. DNS returns CNAME pointing to example.com
    3. DNS then resolves example.com to 192.0.2.1
    4. Client connects to 192.0.2.1

    Common Use Cases

    Subdomain Aliases

    Point multiple subdomains to the same destination:

    www.example.com.     3600    CNAME    example.com.
    blog.example.com.    3600    CNAME    example.com.
    shop.example.com.    3600    CNAME    example.com.

    CDN Integration

    Point your domain to a CDN provider:

    www.example.com.    3600    CNAME    d1234.cloudfront.net.
    static.example.com. 3600    CNAME    example.b-cdn.net.

    Cloud Service Integration

    Point subdomains to cloud platforms:

    app.example.com.    3600    CNAME    myapp.herokuapp.com.
    docs.example.com.   3600    CNAME    example.gitbook.io.

    Email Service Verification

    Many email services require CNAME records:

    em1234.example.com. 3600    CNAME    u1234.wl.sendgrid.net.

    Record Format

    FieldDescriptionExample
    NameSubdomain to aliaswww, blog, api
    TypeRecord typeCNAME
    ContentTarget domain nameexample.com.
    TTLTime to live (seconds)3600

    Important Limitations

    1. Cannot Use at Apex/Root Domain

    CNAME records cannot be used at the root domain (apex):

    # ❌ NOT ALLOWED
    example.com.    CNAME    other.com.
     
    # ✅ ALLOWED
    www.example.com.    CNAME    other.com.

    For apex domains, use ALIAS records instead.

    2. Must Be the Only Record at That Name

    A CNAME cannot coexist with other record types at the same name:

    # ❌ NOT ALLOWED - conflicts with CNAME
    www.example.com.    CNAME    example.com.
    www.example.com.    TXT      "verification=abc123"
     
    # ✅ ALLOWED - CNAME is the only record
    www.example.com.    CNAME    example.com.

    3. Adds Lookup Latency

    Each CNAME introduces an additional DNS lookup, which can increase latency. For performance-critical applications, consider using A/AAAA records directly.

    Adding a CNAME Record

    Using the Dashboard

    1. Navigate to your zone in the DNScale dashboard
    2. Click Add Record
    3. Configure the record:
      • Name: Enter the subdomain (e.g., www, blog)
      • Type: Select CNAME
      • Value: Enter the target domain name
      • TTL: Set the cache duration (default: 3600)
    4. Click Create Record

    Using the API

    Create a CNAME record:

    curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "www",
        "type": "CNAME",
        "content": "example.com",
        "ttl": 3600
      }'

    Point subdomain to CDN:

    curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "cdn",
        "type": "CNAME",
        "content": "d1234567.cloudfront.net",
        "ttl": 3600
      }'

    API Response:

    {
      "status": "success",
      "data": {
        "message": "Record created successfully",
        "record": {
          "id": "encoded-record-id",
          "name": "www.example.com.",
          "type": "CNAME",
          "content": "example.com.",
          "ttl": 3600,
          "disabled": false
        }
      }
    }

    Best Practices

    1. Use trailing dots - The target domain should technically end with a dot (e.g., example.com.), though DNScale handles this automatically

    2. Check for conflicts - Ensure no other records exist at the CNAME name

    3. Consider TTL carefully - Use shorter TTLs if the target might change (e.g., during CDN migrations)

    4. Don't chain too many CNAMEs - While DNS allows CNAME chains, they add latency and complexity

    5. Use ALIAS for apex - If you need CNAME-like behavior at the root domain, use ALIAS records

    CNAME vs ALIAS vs A Record

    FeatureCNAMEALIASA
    Points toDomain nameDomain nameIP address
    Works at apex❌ No✅ Yes✅ Yes
    Can coexist with other records❌ No✅ Yes✅ Yes
    Extra DNS lookupYesNo (resolved at authoritative)No

    Testing CNAME Records

    Verify your CNAME record with dig:

    dig CNAME www.example.com
     
    # Follow the chain to get the final IP
    dig +trace www.example.com
    • A - Direct IPv4 mapping
    • AAAA - Direct IPv6 mapping
    • ALIAS - CNAME-like behavior for apex domains

    Conclusion

    CNAME records are invaluable for simplifying DNS management, especially when integrating with third-party services. Understanding their limitations—particularly around apex domains and record coexistence—helps you make the right choice between CNAME, ALIAS, and direct A/AAAA records.