Weight configuration in Alibaba Cloud DNS allows you to assign multiple record values, such as IP addresses or CNAMEs, to the same host record and same DNS line. When responding to DNS queries, Alibaba Cloud DNS returns a record value based on a preset weight ratio, distributing responses probabilistically. This directs traffic across different servers to achieve load balancing.
Prerequisites
Weight configuration requires multiple A, CNAME, or AAAA records for the same host record and DNS line.
When weight configuration is disabled:
-
For A, AAAA, NS, MX, and TXT records, Alibaba Cloud DNS returns all records for the specified DNS line. The local DNS server selects a record to return to the client. If all addresses are returned, the client randomly selects one.
-
For CNAME records, Alibaba Cloud DNS returns only one of the available records.
Limitations
|
Limitation |
Supported |
Not supported |
|
Record type |
A, CNAME, and AAAA records. |
Other record types. |
|
Record status |
Enabled records. |
Paused or locked records, and wildcard DNS record. |
|
DNS record limit |
Maximum number of weighted DNS records per domain per DNS line: 10 for the Free Edition and 90 for paid editions. |
Not applicable. |
|
Weight value rules |
Weight values can be set from 0 to 100. The default weight ratio is 1:1. If a weight is set to 0, Alibaba Cloud DNS does not return the corresponding record value. |
Not applicable. |
|
DNS line |
You can configure weighted A records for the default line or for specific DNS lines. Note
Weights for different DNS lines are independent of each other. |
Mixing weighted and non-weighted routing for the same host record across different DNS lines. |
Procedure
Add a record
-
Go to the Alibaba Cloud DNS - Authoritative Zone page. Click the target domain name to open the Settings page.
-
On the Settings page, click Add Record.
By default, a weight ratio of 1:1:1 is configured when you add multiple records for the same host record and DNS line. Alibaba Cloud DNS then returns IP addresses based on this ratio.
In the Add Record panel, set Record type to A, enter the Host record, and select Default for DNS line. Set TTL to 10 minutes (Recommended). Set the record value load policy to Weight, add multiple record values such as
223.5.5.xand223.6.6.x, and set the weight for each to 1.
Modify a record set
-
Go to the Alibaba Cloud DNS - Authoritative Zone page. Click the target domain name to open the Settings page.
-
On the Settings page, click the drop-down arrow
next to Edit and select Edit Record Set. -
In the dialog box, you can modify the record values and their weights.
Set the record value load policy to Weight, and modify the weight for each record value in the record value set.
How it works
Behavior without weight configuration
Assume you have three servers with the IP addresses 1.1.XX.XX, 2.2.XX.XX, and 3.3.XX.XX. These servers provide the same service for a single domain and have the following A records configured:
|
Type |
Host record |
DNS line |
Value |
|
A |
www |
Default |
1.1.XX.XX |
|
A |
www |
Default |
2.2.XX.XX |
|
A |
www |
Default |
3.3.XX.XX |
When a local DNS server queries Alibaba Cloud DNS, it receives all three DNS records. If the local DNS server forwards all three IP addresses to the client, the client's browser randomly selects one to access.
For an authoritative DNS service that does not provide DNS-based load balancing, this approach can reduce the load on a single server to some extent. However, it cannot distinguish between servers or reflect the current operational status of each server.
Behavior with default weights
With weight configuration enabled and using the default 1:1:1 ratio, Alibaba Cloud DNS round-robins the three A records, returning their IP addresses sequentially. The DNS resolution results are as follows:
Query from Region1 returns 1.1.XX.XX
Query from Region2 returns 2.2.XX.XX
Query from Region3 returns 3.3.XX.XX
Query from Region4 returns 1.1.XX.XX
Query from Region5 returns 2.2.XX.XX
Query from Region6 returns 3.3.XX.XX
...
Behavior with custom weights
After setting custom weights, Alibaba Cloud DNS returns responses according to the preset ratio, which allows you to distribute traffic. For example, if you set the weight ratio for the three records to 2:1:1, the DNS resolution results are as follows:
Query from Region1 returns 1.1.XX.XX
Query from Region2 returns 2.2.XX.XX
Query from Region3 returns 3.3.XX.XX
Query from Region4 returns 1.1.XX.XX
Query from Region5 returns 1.1.XX.XX
Query from Region6 returns 2.2.XX.XX
...
If you notice that DNS query results occasionally do not match the configured weight ratio during testing, this is expected behavior. Weighted round-robin is a coarse-grained traffic scheduling method that applies to requests from a local DNS server. Each local DNS server queries the authoritative DNS server (Alibaba Cloud DNS) only once per TTL period.
For example, consider a scenario where users from Shanghai use local DNS server A and users from Beijing use local DNS server B. When local DNS server A and local DNS server B send query requests to Alibaba Cloud DNS, Alibaba Cloud DNS responds according to your configured weight policy. However, for the duration of the TTL, all users who share the same local DNS server will receive the same cached resolution result.