Wildcard DNS uses an asterisk ( * ) as the host record to point all subdomains to a single IP address (the record value). For example, if you set a wildcard record *.example.com for the domain example.com, all of its subdomains, such as a.example.com and b.example.com, will resolve to the same IP address as *.example.com.
Scenarios
Use wildcard DNS to redirect an entire domain, direct all subdomains to a single entry point, or resolve unmatched subdomains to a fallback service page.
Supported record types
A record, AAAA record, CNAME record, NS record, MX record, TXT record, CAA record, explicit URL/implicit URL, SVCB record, and HTTPS record.
Procedure
-
On the Alibaba Cloud DNS – Public Zone page, click the target domain to go to the Resolution Settings page.
-
On the Settings page, click the Add Record button.
In the Add Record panel, set record type to A - Maps a domain name to an IPv4 address, host record to
*(wildcard, with the domain suffix.cloud-example.net), Resolution Request Source to default line, TTL to 10 minutes, and Record Value Load Balancing Policy to round-robin. Then, in the Record Value Set area, enter the target IPv4 address and click + Add Item. -
Verify the record.
Run the
dig a.example.netcommand and check that the returned DNS record matches the record value you added.
Wildcard DNS query rules
-
A DNS query first attempts to match a line, and then a domain name.
-
On the same line, an exact domain match takes precedence over a wildcard match. The DNS resolver uses a wildcard record only if no other records match the query.
-
If a wildcard query matches a smart line but an exact-match query matches the default line, the exact-match record on the default line is used for resolution.
Example 1
|
Host record |
Type |
Line |
Value |
|
www.example.com |
A |
default line |
1.1.1.1 |
|
api.example.com |
A |
default line |
2.2.2.2 |
|
*.example.com |
A |
default line |
3.3.3.3 |
-
A query for
www.example.com→ returns1.1.1.1(matches the exact A record, not the wildcard record). -
A query for
api.example.com→ returns2.2.2.2(matches the exact A record, not the wildcard record). -
A query for
test.example.com→ returns3.3.3.3because it finds no exact-match record and falls back to the wildcard record. -
A query for the second-level subdomain
abc.def.example.com→ returns3.3.3.3because it finds no exact-match record and falls back to the wildcard record.
Example 2
Wildcard DNS records are configured for example.com on the China Unicom, China Telecom, and China Mobile lines:
|
Host record |
Type |
Line |
Value |
|
* |
A |
China Unicom |
1.1.x.x |
|
* |
A |
China Telecom |
1.1.x.x |
|
* |
A |
China Mobile |
1.1.x.x |
|
www |
A |
default line |
4.4.x.x |
When users on the China Unicom, China Telecom, and China Mobile lines access www.example.com, the domain resolves to 4.4.x.x. Although the query matches a wildcard record on an ISP-specific line, an exact match exists on the default line, so the resolver returns the default-line record instead.
To have users from China Unicom, China Telecom, and China Mobile resolve www.example.com to 1.1.XX.XX, add a DNS record with www as the host record for example.com under each of the three ISP lines, as shown below.
|
Host record |
Type |
Line |
Value |
|
* |
A |
China Unicom |
1.1.x.x |
|
www |
A |
China Unicom |
1.1.x.x |
|
* |
A |
China Telecom |
1.1.x.x |
|
www |
A |
China Telecom |
1.1.x.x |
|
* |
A |
China Mobile |
1.1.x.x |
|
www |
A |
China Mobile |
1.1.x.x |
|
www |
A |
default line |
4.4.x.x |
Now, when users on the China Unicom, China Telecom, and China Mobile lines access www.example.com, the domain resolves to 1.1.x.x.