# Azion CLI dns-record

The Azion CLI `dns-record` commands create, list, describe, update, and delete the records of an [Edge DNS](/en/documentation/platform/edge-dns/) zone. A record is one name, one type, and the values Edge DNS answers with for that name. A record belongs to one zone, so every command takes the `--zone-id` of that zone. The fields of a record are on [Zones and records](/en/documentation/platform/edge-dns/zones-and-records/). The options every command accepts, such as `--format`, `--out`, and `-y`, are on [Global options](/en/documentation/devtools/cli/globals/).

---

## Create

`azion create dns-record` creates a record in a zone, with the name, type, and values you pass:

```bash
azion create dns-record [flags]
```

| Flag            | Short | Type    | Default | Description                                                                                                                                                                         |
| --------------- | ----- | ------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--description` | —     | string  | —       | Description of the record. Used only when `--policy` is `weighted`.                                                                                                                 |
| `--file`        | —     | string  | —       | Path to a JSON file with the attributes of the record. Use `-` to read the JSON from standard input.                                                                                |
| `--name`        | —     | string  | —       | Name of the record inside the zone, such as `www`.                                                                                                                                  |
| `--policy`      | —     | string  | —       | Routing policy of the record: `simple` or `weighted`.                                                                                                                               |
| `--rdata`       | —     | strings | —       | Values of the record. Repeat the flag or pass a comma-separated list for several values.                                                                                            |
| `--ttl`         | —     | int     | —       | Time to live (TTL) of the record, in seconds.                                                                                                                                       |
| `--type`        | —     | string  | —       | Type of the record, such as `A`, `AAAA`, `CNAME`, `MX`, `TXT`, or `NS`. The types and their value formats are on [Record types](/en/documentation/platform/edge-dns/record-types/). |
| `--weight`      | —     | int     | —       | Weight of the record. Used only when `--policy` is `weighted`.                                                                                                                      |
| `--zone-id`     | —     | int     | —       | **Required**. ID of the zone that holds the record. Without it, the command asks for the ID of the zone.                                                                            |

This command creates an `A` record named `www` with two values and a TTL of 3600 seconds:

```bash
azion create dns-record --zone-id 1234 --name www --type A --rdata '192.0.2.1,192.0.2.2' --ttl 3600
```

The command prints the ID of the record:

```text
Created DNS record with ID 100001
```

`--rdata` splits its value at every comma, so a value that contains a comma becomes several values. With `--rdata 'v=spf1 include:a.example.com,b.example.com ~all'`, the record stores `v=spf1 include:a.example.com` and `b.example.com ~all` as two values. To keep the comma inside one value, wrap the value in double quotes inside the single quotes, or pass the value in a JSON file with `--file`.

This command creates a `TXT` record named `spf2` whose one value contains a comma:

```bash
azion create dns-record --zone-id 1234 --name spf2 --type TXT --rdata '"v=spf1 include:a.example.com,b.example.com ~all"' --ttl 300
```

The command prints the ID of the record, which stores the value whole:

```text
Created DNS record with ID 100003
```

A `--type` value that is not a record type, such as `ZZZ`, is refused with this error:

```text
Error: Failed to create the DNS record: ["\"ZZZ\" is not a valid choice."]. Check your settings and try again. If the error persists, contact Azion support.
```

---

## List

`azion list dns-record` lists the records of a zone, 50 to a page:

```bash
azion list dns-record [flags]
```

| Flag          | Short | Type   | Default | Description                                                                                         |
| ------------- | ----- | ------ | ------- | --------------------------------------------------------------------------------------------------- |
| `--details`   | —     | —      | —       | Accepted, but adds no columns: the list keeps the `ID`, `NAME`, `TYPE`, `TTL`, and `RDATA` columns. |
| `--filter`    | —     | string | —       | Name to filter the list by.                                                                         |
| `--order-by`  | —     | string | —       | Field to sort the list by.                                                                          |
| `--page`      | —     | int    | `1`     | Number of the page to return.                                                                       |
| `--page-size` | —     | int    | `50`    | Number of records on each page.                                                                     |
| `--zone-id`   | —     | int    | —       | **Required**. ID of the zone whose records the command lists.                                       |

This command lists the records of the zone with ID `1234`:

```bash
azion list dns-record --zone-id 1234
```

The command prints one row per record:

```text
ID      NAME  TYPE  TTL   RDATA
100001  www   A     3600  192.0.2.1, 192.0.2.2
100002  spf   TXT   300   v=spf1 include:a.example.com, b.example.com ~all
100003  spf2  TXT   300   v=spf1 include:a.example.com,b.example.com ~all
100004  txt   TXT   300   v=spf1 include:a.example.com,b.example.com ~all
```

The `RDATA` column joins the values of a record with a comma and a space. The `spf` record holds two values and the `spf2` record holds one, and the two rows look almost the same. To read each value apart, describe the record with `--format json`.

---

## Describe

`azion describe dns-record` prints the settings of one record:

```bash
azion describe dns-record [flags]
```

| Flag          | Short | Type | Default | Description                                         |
| ------------- | ----- | ---- | ------- | --------------------------------------------------- |
| `--record-id` | —     | int  | —       | **Required**. ID of the record to describe.         |
| `--zone-id`   | —     | int  | —       | **Required**. ID of the zone that holds the record. |

This command describes the record with ID `100001`:

```bash
azion describe dns-record --zone-id 1234 --record-id 100001
```

The command prints the name, the type, the values, and the routing settings of the record:

```text
ID:            100001
Description:
Name:          www
TTL:           3600
Type:          A
Rdata:         ["192.0.2.1","192.0.2.2"]
Policy:        simple
Weight:        255
```

With `--format json`, the command prints `description`, `id`, `name`, `policy`, `rdata`, `ttl`, `type`, and `weight`, with `rdata` as an array of one item per value. A record created without `--policy` holds the policy `simple` and the weight `255`.

A record ID that does not exist in the zone fails with this error:

```text
Error: Failed to describe the DNS record: The given ID or API's endpoint doesn't exist or isn't available. Check that the identifying information is correct. Check your settings and try again. If the error persists, contact Azion support.
```

---

## Update

`azion update dns-record` changes the name, type, values, TTL, or routing settings of a record:

```bash
azion update dns-record [flags]
```

| Flag            | Short | Type    | Default | Description                                                                                      |
| --------------- | ----- | ------- | ------- | ------------------------------------------------------------------------------------------------ |
| `--description` | —     | string  | —       | Description of the record. Used only when `--policy` is `weighted`.                              |
| `--file`        | —     | string  | —       | Path to a JSON file with the attributes to change. Use `-` to read the JSON from standard input. |
| `--name`        | —     | string  | —       | New name of the record inside the zone.                                                          |
| `--policy`      | —     | string  | —       | Routing policy of the record: `simple` or `weighted`.                                            |
| `--rdata`       | —     | strings | —       | Values of the record. Repeat the flag or pass a comma-separated list for several values.         |
| `--record-id`   | —     | int     | —       | **Required**. ID of the record to update.                                                        |
| `--ttl`         | —     | int     | —       | Time to live (TTL) of the record, in seconds.                                                    |
| `--type`        | —     | string  | —       | Type of the record, such as `A`, `AAAA`, `CNAME`, `MX`, `TXT`, or `NS`.                          |
| `--weight`      | —     | int     | —       | Weight of the record. Used only when `--policy` is `weighted`.                                   |
| `--zone-id`     | —     | int     | —       | **Required**. ID of the zone that holds the record.                                              |

`--rdata` replaces every value of the record and splits its value at every comma, as on create.

This command sets one value and a TTL of 7200 seconds on the record with ID `100001`:

```bash
azion update dns-record --zone-id 1234 --record-id 100001 --rdata 192.0.2.3 --ttl 7200
```

The command confirms the update:

```text
DNS record 100001 was updated
```

The record then holds the single value `192.0.2.3`, and its name and type stay `www` and `A`.

---

## Delete

`azion delete dns-record` deletes a record from a zone:

```bash
azion delete dns-record [flags]
```

| Flag          | Short | Type | Default | Description                                         |
| ------------- | ----- | ---- | ------- | --------------------------------------------------- |
| `--record-id` | —     | int  | —       | **Required**. ID of the record to delete.           |
| `--zone-id`   | —     | int  | —       | **Required**. ID of the zone that holds the record. |

This command deletes the record with ID `100001`:

```bash
azion delete dns-record --zone-id 1234 --record-id 100001
```

The command confirms the deletion:

```text
DNS record 100001 was successfully deleted
```

---

## Use a JSON file

`azion create dns-record` and `azion update dns-record` read the attributes of the record from a JSON file with `--file`. The zone stays on the command line as `--zone-id`, and on update the record stays on the command line as `--record-id`.

In the file, `rdata` is an array with one item per value, so a comma inside a value stays part of it. This file creates a `TXT` record named `txt` with one value and a TTL of 300 seconds:

```json
{
  "name": "txt",
  "type": "TXT",
  "rdata": ["v=spf1 include:a.example.com,b.example.com ~all"],
  "ttl": 300
}
```

Pass the file to the create command:

```bash
azion create dns-record --zone-id 1234 --file rec-create.json
```

The command prints the ID of the record:

```text
Created DNS record with ID 100004
```

On update, the command changes only the fields in the file, and the fields you leave out keep their values. This file replaces the value of the record and sets a TTL of 600 seconds:

```json
{
  "rdata": ["v=spf1 -all"],
  "ttl": 600
}
```

Pass the file to the update command:

```bash
azion update dns-record --zone-id 1234 --record-id 100004 --file rec-update.json
```

The command confirms the update:

```text
DNS record 100004 was updated
```

The record keeps the name `txt` and the type `TXT`, and holds the value `v=spf1 -all` with a TTL of 600 seconds.

---

## Related resources

- [Global options](/en/documentation/devtools/cli/globals.md): The options every command accepts, such as `--format`, `--out`, and `-y`.
- [Zones and records](/en/documentation/platform/edge-dns/zones-and-records.md): Every record field, its Console label, its API field, and its CLI flag.
- [Azion CLI dns-zone](/en/documentation/devtools/cli/resources/dns-zone.md): The commands that create and manage the zones that hold the records.
- [Azion CLI dnssec](/en/documentation/devtools/cli/resources/dnssec.md): The commands that read the DNSSEC state of a zone and turn signing on or off.
