---
name: azion-point-a-subdomain-with-a-cname-record
description: >-
  Make a subdomain an alias of another hostname with an Edge DNS CNAME record, from Azion Console, the Azion CLI, or the API, and check the answer.
---

# Point a subdomain with a CNAME record

You can point a subdomain to another host with a CNAME record in [Edge DNS](/en/documentation/platform/edge-dns/) from Azion Console, the Azion CLI, or the Azion API. The record below makes `blog.example.com` an alias of `www.example.com`, so a query for `blog` gets the address of `www`. A CNAME cannot be named `@`: to point the root domain, refer to [Point an apex domain with ANAME](/en/documentation/guides/application-security/dns/access-root-domain/) instead.

---

Select an interface. The prerequisites and the procedure below switch with it.

## Prerequisites

- A zone for your domain in Edge DNS. To create one, refer to [Create, edit, or delete a zone](/en/documentation/guides/application-security/dns/edge-dns-configure-main-settings/).
- The hostname the alias points to. This example uses `www.example.com`, an A record on `www` in the same zone that answers `192.0.2.1`.
- The **Edit Edge DNS** permission. It requires **View Edge DNS**. Refer to [Teams permissions](/en/documentation/fundamentals/teams-permissions/).

**Console**

- Access to Azion Console. To sign in, refer to [Access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).

**CLI**

- The [Azion CLI](/en/documentation/devtools/cli/) installed and authorized.
- The ID of the zone. `azion list dns-zone` prints it in the `ID` column.

**API**

- A [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/) and `curl`.
- The `id` of the zone.

---

## Add the CNAME record

The record name is relative to the zone: you enter `blog`, and Edge DNS serves it as `blog.example.com`. The value is the one hostname the alias points to. Replace `example.com` with your domain in every step.

**Console**

To add the CNAME record in Azion Console:

1. **Open the Edge DNS page**

   Access [Azion Console](https://console.azion.com/) > **Edge DNS**.

2. **Open the zone**

   On the **Zones** page, select the row of the zone.

3. **Select the Records tab**

4. **Select + Record**

   The **Create Record** drawer opens.

5. **Enter the subdomain**

   In **Name**, enter `blog`. The Console shows your domain after the field and adds it for you.

6. **Select the CNAME type**

   In **Record Type**, select *CNAME - Canonical name*.

7. **Keep the TTL**

   Keep **TTL (seconds)** at `3600`.

8. **Enter the target hostname**

   In **Value**, enter `www.example.com`.

9. **Select Save**

The Console shows `Edge DNS Record has been created`, and `blog` appears in the **Records** table.

**CLI**

To add the CNAME record with the Azion CLI, replace `<zone-id>` with the ID of your zone and run:

```bash
azion create dns-record --zone-id <zone-id> --name blog --type CNAME --rdata www.example.com --ttl 3600
```

The command prints the ID of the record:

```text
Created DNS record with ID 100774
```

The zone holds the alias. Pass `blog` alone in `--name`: a name typed with the domain is served with the domain twice.

**API**

To add the CNAME record with the Azion API, send a `POST` request to the zone's records endpoint. Replace `<zone-id>` with the `id` of your zone and `[TOKEN VALUE]` with your personal token:

```bash
curl -X POST https://api.azion.com/v4/workspace/dns/zones/<zone-id>/records \
  -H "Authorization: Token [TOKEN VALUE]" \
  -H "Content-Type: application/json" \
  -d '{"name":"blog","type":"CNAME","rdata":["www.example.com"],"ttl":3600}'
```

A `201` returns the record:

```json
{
  "state": "executed",
  "data": {
    "id": 100177,
    "description": "",
    "name": "blog",
    "ttl": 3600,
    "type": "CNAME",
    "rdata": ["www.example.com"],
    "policy": "simple",
    "weight": 255
  }
}
```

The zone holds the alias. `rdata` carries the one target hostname, and `policy` and `weight` keep their defaults.

Once `blog` holds the CNAME, it holds no other record type: Edge DNS refuses an MX or CAA record on `blog` with `19018`. For every CNAME rule and its error, refer to [Record types](/en/documentation/platform/edge-dns/record-types/#cname).

---

## Check the answer

Ask Azion's nameserver directly, without your resolver's cache. This check works before you delegate the domain to Azion.

> **Caution**
>
> Query `blog` only after you save the record. A name queried before its record exists is answered `NXDOMAIN` for up to one hour, the SOA minimum.

To query `ns1.aziondns.net` for the alias, replace `example.com` with your domain:

```bash
dig +short @ns1.aziondns.net blog.example.com A
```

The nameserver returns the target hostname, then the address of the target:

```text
www.example.com.
192.0.2.1
```

The target is in the same zone, so Edge DNS answers the CNAME and the A record of `www` in one response. A name that nobody queried before you saved it answers within seconds. A later change to the record can take a few minutes to reach every nameserver. For how answers are cached, refer to [How Edge DNS works](/en/documentation/platform/edge-dns/how-it-works/#caching-and-propagation).

If the command prints nothing, refer to [A new record returns NXDOMAIN](/en/documentation/platform/edge-dns/troubleshooting/#a-new-record-returns-nxdomain).

---

## Next steps

- [Point an apex domain with ANAME](/en/documentation/guides/application-security/dns/access-root-domain.md): Answer for the root domain, where a CNAME is refused.
- [Record types](/en/documentation/platform/edge-dns/record-types.md#cname): Every CNAME rule and the error the API returns for each.
- [Add, edit, or delete a record](/en/documentation/guides/application-security/dns/add-records.md): Change the target of the alias, or delete it.
- [Migrate nameservers to Azion](/en/documentation/guides/platform/migration/migrate-ns-to-azion.md): Delegate the domain so public resolvers ask Edge DNS.
