Wildcard record
A wildcard DNS record uses an asterisk (*) as the hostname to match requests for all subdomain and point them to a single IP address (record value). For instance, setting up a DNS record for *.example.com ensures that all subdomains, such as a.example.com and b.example.com, automatically resolve to the same IP address as *.example.com.
Use cases
Use wildcard records to redirect an entire domain, direct certain subdomains to a single entry point, or direct unmatched requests to a fallback service page.
Supported record types
A record, AAAA record, CNAME record, ALIAS record, NS record, MX record, TXT record, CAA record, explicit/implicit URL forwarding, SVCB record, and HTTPS record.
Add a wildcard record
On the Alibaba Cloud DNS – Public Zone page, click the target domain to go to the Settings page.
On the Settings page, click Add Record.
In the Add Record panel, select a supported record type, set the hostname to
*, and enter the record value. You can keep the default values for the remaining fields or configure them as needed. Then, click OK.Verify that the record has taken effect.
Run the
digcommand to query a subdomain that has no existing record (for example,dig a.example.com), and verify that the returned value matches the record value you configured.
Wildcard DNS query rules
DNS queries prioritize domain name matching and then selects a resolution line among the records for the matched domain name.
Within the same line, an exact domain record takes precedence over a wildcard record. A wildcard record applies only when no exact record exists at the queried name.
If a query matches a wildcard record configured for a specific smart resolution line, and also matches an exact domain record configured for the default line, the exact domain record under the default line takes effect.
Example 1
Hostname | Type | Line | Record value |
www | A | Default line | 1.1.1.1 |
api | A | Default line | 2.2.2.2 |
* | A | Default line | 3.3.3.3 |
A query for
www.example.comreturns1.1.1.1(matches the exact A record, not the wildcard record).A query for
api.example.comreturns2.2.2.2(matches the exact A record, not the wildcard record).A query for
test.example.comreturns3.3.3.3(no exact match is found, so the wildcard record is used).A query for the multi-level subdomain
abc.def.example.comreturns3.3.3.3(no exact match is found, so the wildcard record is used).
Example 2
Wildcard DNS records are configured for example.com on the China Unicom, China Telecom, and China Mobile lines:
Hostname | Type | Line | Record 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 |
With this configuration, when users on the China Unicom, China Telecom, and China Mobile lines access www.example.com, the query 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 hostname for example.com under each of the three ISP lines, as shown below.
Hostname | Type | Line | Record 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 |
With these explicit records added, when users on China Unicom, China Telecom, or China Mobile lines access www.example.com, the query resolves to 1.1.x.x.