---
name: azion-weight-records-to-balance-traffic
description: >-
  Spread the answers for one name across several addresses with weighted records in Edge DNS, from Azion Console, the Azion CLI, or the API.
---

# Weight records to balance traffic

You can weight records to balance traffic in [Edge DNS](/en/documentation/platform/edge-dns/) from Azion Console, the Azion CLI, or the Azion API. Several records share one name and type, and each answer carries the value of one of them, chosen in proportion to its weight. To add a record that answers with all of its values at once, refer to [Add, edit, or delete a record](/en/documentation/guides/application-security/dns/add-records/) instead.

---

Select your interface once. The prerequisites and every task below show only that path.

## Prerequisites

- A zone for your domain. To create one, refer to [Create, edit, or delete a zone](/en/documentation/guides/application-security/dns/edge-dns-configure-main-settings/).
- The **Edit Edge DNS** permission. It requires **View Edge DNS**. Refer to [Teams permissions](/en/documentation/fundamentals/teams-permissions/).
- `dig` on your machine, to check the answers. To install it, refer to [Query a zone with dig](/en/documentation/guides/application-security/dns/run-the-dig-command/).

**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. A `GET` request to `https://api.azion.com/v4/workspace/dns/zones` returns each zone with its `id`.
- For every endpoint and field of the API, refer to the [Azion API reference](https://api.azion.com/).

---

## Add the weighted records

This example adds three A records on the name `lb`, one per address, with weights 50, 20, and 30. Over many answers, `192.0.2.21` carries about half of them, `192.0.2.22` a fifth, and `192.0.2.23` the rest. Replace the addresses with your own, and `example.com` with your domain.

Each record uses a TTL of 20 seconds, so resolvers choose again sooner. A short TTL also makes resolvers ask more often, and every query counts toward your plan's [included usage](/en/documentation/platform/edge-dns/limits/#included-usage-per-plan).

**Console**

To add the first 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, then select the **Records** tab.

3. **Select + Record**

   The **Create Record** drawer opens.

4. **Enter the record name**

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

5. **Keep the A record type**

   Keep **Record Type** set to *A - IPv4 Address*.

6. **Set the TTL**

   In **TTL (seconds)**, enter `20`.

7. **Enter the value**

   In **Value**, enter `192.0.2.21`.

8. **Select the weighted policy**

   In the **Policy** section, set **Policy Type** to *Weighted*.

9. **Set the weight**

   In **Weight**, enter `50`. The Console pre-fills `100`.

10. **(Optional) Describe the record**

    In **Description**, enter up to 45 characters that tell this record apart from the others on `lb`, such as `origin weight 50`.

11. **Select Save**

The Console shows `Edge DNS Record has been created`, and the record appears in the **Records** table with `weighted` in the **Policy** column.

Repeat the steps for the other two records. Keep **Name** `lb`, **Record Type** A, and the TTL, and change only the value and the weight: `192.0.2.22` with weight `20`, then `192.0.2.23` with weight `30`. The **Records** table then lists three `lb` rows.

**CLI**

To add the three records with the Azion CLI, run one command per record. Replace `<zone-id>` with the ID of your zone:

```bash
azion create dns-record --zone-id <zone-id> --name lb --type A --rdata 192.0.2.21 --ttl 20 --policy weighted --weight 50 --description "origin weight 50"
azion create dns-record --zone-id <zone-id> --name lb --type A --rdata 192.0.2.22 --ttl 20 --policy weighted --weight 20 --description "origin weight 20"
azion create dns-record --zone-id <zone-id> --name lb --type A --rdata 192.0.2.23 --ttl 20 --policy weighted --weight 30 --description "origin weight 30"
```

Each command prints the ID of its record:

```text
Created DNS record with ID 100780
```

The CLI uses `--weight` and `--description` only when `--policy` is `weighted`. Never include the domain in `--name`: Edge DNS adds it.

To check the records, list the records of the zone:

```bash
azion list dns-record --zone-id <zone-id>
```

The list shows the three records on `lb`, each with its own ID:

```text
ID      NAME  TYPE  TTL  RDATA
…
100188  lb    A     20   192.0.2.21
100189  lb    A     20   192.0.2.22
100190  lb    A     20   192.0.2.23
…
```

The zone holds the three weighted records. Record their IDs: a later change to a weight uses them.

**API**

To add the first 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":"lb","type":"A","rdata":["192.0.2.21"],"ttl":20,"policy":"weighted","weight":50,"description":"origin weight 50"}'
```

A `201` returns the record:

```json
{
  "state": "executed",
  "data": {
    "id": 100188,
    "description": "origin weight 50",
    "name": "lb",
    "ttl": 20,
    "type": "A",
    "rdata": ["192.0.2.21"],
    "policy": "weighted",
    "weight": 50
  }
}
```

Send the same request twice more, with the same `name`, `type`, `ttl`, and `policy`. Change only the value, the weight, and the description:

```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":"lb","type":"A","rdata":["192.0.2.22"],"ttl":20,"policy":"weighted","weight":20,"description":"origin weight 20"}'

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":"lb","type":"A","rdata":["192.0.2.23"],"ttl":20,"policy":"weighted","weight":30,"description":"origin weight 30"}'
```

Each request returns `201` with its record. The zone holds three weighted records on `lb`. Record each `id`: a later change to a weight uses it. A record sent without `weight` gets `255`.

The weighted policy works on A, AAAA, CNAME, ANAME, and MX records. A TXT or NS record with `policy` set to `weighted` is refused with `19017`. For every field and its bounds, refer to [Zones and records](/en/documentation/platform/edge-dns/zones-and-records/#record-fields).

---

## Check the weighted answers

Query Azion's nameserver directly, without your resolver's cache, to see which address it answers.

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

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

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

The nameserver returns one address, the value of the record it chose:

```text
192.0.2.21
```

Each answer carries one address, never the three. Run the query again right away and the same address returns: the nameserver answers from a cache that counts the record's TTL down. Run it again after each 20-second TTL, over several minutes, and the other addresses appear. Over many answers, each address answers in proportion to its weight. For how the nameserver chooses, refer to [How Edge DNS works](/en/documentation/platform/edge-dns/how-it-works/#record-policies).

A new name nobody queried before it existed answers within seconds. A change to an existing record can take a few minutes to reach every nameserver. For the details, refer to [Caching and propagation](/en/documentation/platform/edge-dns/how-it-works/#caching-and-propagation).

---

## Take an address out of rotation

A record with weight `0` stays in the zone and is never answered. Set a weight of `0` to stop answers for an address without deleting its record, and restore the weight to bring it back. Before you delete a weighted record, set its weight to `0` first, as [Best practices for Edge DNS](/en/documentation/platform/edge-dns/best-practices/#set-a-weight-of-0-before-you-delete-a-weighted-record) explains.

**Console**

To set a record's weight to `0` 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, then select the **Records** tab.

3. **Open the record**

   Select the row of the record. The **Edit Record** drawer opens.

4. **Set the weight to 0**

   In **Weight**, enter `0`.

5. **Select Save**

The Console shows `Edge DNS Record has been updated`, and the **Weight** column of the row reads `0`.

**CLI**

To set a record's weight to `0` with the Azion CLI, replace `<zone-id>` and `<record-id>` with the IDs of the zone and the record:

```bash
azion update dns-record --zone-id <zone-id> --record-id <record-id> --weight 0
```

The command confirms the update:

```text
DNS record 100189 was updated
```

The record keeps its weighted policy, and its weight is `0`. To check it, run `azion describe dns-record --zone-id <zone-id> --record-id <record-id>`, which prints `Policy: weighted` and `Weight: 0`.

**API**

To set a record's weight to `0` with the Azion API, send a `PATCH` request with `weight` set to `0`. Replace `<zone-id>` and `<record-id>` with the `id` of the zone and of the record:

```bash
curl -X PATCH https://api.azion.com/v4/workspace/dns/zones/<zone-id>/records/<record-id> \
  -H "Authorization: Token [TOKEN VALUE]" \
  -H "Content-Type: application/json" \
  -d '{"weight":0}'
```

A `200` returns the record with weight `0`:

```json
{
  "state": "executed",
  "data": {
    "id": 100190,
    "description": "origin weight 30",
    "name": "lb",
    "ttl": 20,
    "type": "A",
    "rdata": ["192.0.2.23"],
    "policy": "weighted",
    "weight": 0
  }
}
```

A `PATCH` changes only the fields you send, so the record keeps its value and its policy.

Resolvers that cached the address keep it until its TTL expires, and the change can take a few minutes to reach every nameserver. After that, the other records carry every answer for the name.

---

## Next steps

- [How Edge DNS works](/en/documentation/platform/edge-dns/how-it-works.md#record-policies): How a weighted answer is chosen and cached.
- [Zones and records](/en/documentation/platform/edge-dns/zones-and-records.md#record-fields): Every record field, its bounds, and its default.
- [Add, edit, or delete a record](/en/documentation/guides/application-security/dns/add-records.md): Change or remove the records of a zone.
- [Troubleshoot Edge DNS](/en/documentation/platform/edge-dns/troubleshooting.md#a-weighted-record-always-returns-the-same-address): Fix a weighted record that returns one address.
