What is wildcard DNS resolution? Why should we be cautious about enabling wildcard DNS resolution?
When it comes to configuring various DNS records, besides the regular A and CNAME records, there's another feature that seems very convenient but requires extra caution: "wildcard DNS." Simply put, wildcard DNS involves setting a special DNS record under a domain name that can match all subdomains not explicitly specified. The common practice is to add a DNS record with the asterisk (*) as the host record in the DNS management platform, such as ".example.com". This asterisk record acts like a wildcard; any access request to a non-existent subdomain will be captured by this rule and resolved to the target IP address or CNAME you specified. For example, if you configure a wildcard DNS record for example.com, pointing *.example.com to 1.2.3.4, then regardless of whether someone accesses a.example.com, b.example.com, or any subdomain you've never configured separately, such as xyzabc123.example.com, the DNS will return the IP address 1.2.3.4. In other words, you've "covered" all possible subdomains at once, without needing to add a separate record for each subdomain. On the surface, wildcard DNS seems like a time-saving and labor-saving tool. For example, if you've built a personal blog or SaaS platform and want each user to have an independent subdomain, but don't want to manually add DNS records for each new user in the backend, a wildcard record can automatically point all undefined subdomains to your server entry point. The program on the server then uses the Host field in the HTTP request header to determine which subdomain the user is accessing and responds accordingly. This model is very common in products that provide multi-tenant services and custom subdomains. Blog platforms and online website building tools heavily rely on wildcard DNS to reduce operational costs. Additionally, if you have a short link service that needs frequent changes, or want to test the traffic distribution of random subdomains, wildcard DNS can greatly reduce your configuration burden.
However, precisely because of its "all-encompassing" nature, once wildcard DNS is enabled, it can bring a series of unexpected security and operational problems. The first and foremost risk is domain hijacking and malicious exploitation. Imagine if your domain example.com had wildcard DNS enabled and pointed to one of your servers. Attackers could easily create arbitrary subdomains to send requests to you, such as phishing.example.com, login.example.com, or even use your domain as a springboard for phishing websites. Because your wildcard DNS records will resolve these malicious subdomains to your server's IP address, attackers only need to deploy a malicious page on your server or exploit vulnerabilities to inject malware, misleading visitors into believing these subdomains are official sites. Worse still, if attackers discover this wildcard DNS feature, they might exploit search engine crawlers to have a large number of invalid subdomains indexed by search engines, resulting in thousands of spam pages under your main domain, severely impacting your website's reputation and SEO ranking. Many website owners have had their main domain penalized or even blacklisted by search engines because they enabled wildcard DNS without proper access control, leading to black hat SEO practices.
Secondly, wildcard DNS significantly increases the burden of DNS resolution and the possibility of cache pollution. Normally, DNS resolvers cache records based on specific subdomains. For example, the resolution result for a.example.com is only cached for a.example.com. However, when wildcard DNS exists, theoretically, every random subdomain that has never been accessed, such as dfhskjfh.example.com, will trigger a new DNS query. Because the local DNS server doesn't have a cache for this specific subdomain, it will query upwards to your authoritative DNS server, ultimately obtaining the IP address returned by the wildcard record. If an attacker uses scripts or a botnet to continuously generate a large number of random, non-existent subdomains to query your DNS server, this constitutes a typical "random subdomain attack," also known as an NXDOMAIN attack (although wildcard DNS doesn't return NXDOMAIN, but rather valid records, making the attack even more dangerous). Your authoritative DNS server may be overwhelmed by tens of thousands of queries per second. Simultaneously, these random subdomains will fill the cache of the recursive DNS server, crowding out the cache space of normal domains and causing a decrease in overall resolution efficiency. Furthermore, due to wildcard DNS resolution, all non-existent subdomains will return a "valid" IP address, making it difficult to distinguish between genuine user requests and malicious scanning or attack traffic from logs, significantly hindering security analysis and anomaly detection.
Moreover, wildcard DNS resolution may conflict with the expected behavior of some applications. For example, you might configure virtual hosts on a server, expecting only specific subdomains (such as www.example.com and api.example.com) to be correctly processed, while other unconfigured subdomains should return 403 or 404 errors. However, because of wildcard DNS, all subdomains can resolve to your server's IP address, forcing the server's web application to determine whether to serve the request using the Host field in the HTTP request header. If the program logic is inadequate or fails to properly handle unknown subdomains, attackers could bypass access controls by constructing special Host headers, or even exploit configuration errors leading to vulnerabilities. More problematic is that if you configure specific subdomain DNS records simultaneously—for example, mail.example.com pointing to a mail server's IP while a wildcard DNS record points to a web server's IP—this is legal because specific records have higher priority than wildcard records. However, if you accidentally delete a specific subdomain record during subsequent maintenance, it will be "caught" by the wildcard DNS record, causing a service that should have been inaccessible to suddenly become accessible, pointing to the wrong server. This makes troubleshooting extremely difficult.
Furthermore, enabling wildcard DNS also affects SSL/TLS certificate deployment. If you want to enable HTTPS for all subdomains, you must use a wildcard certificate (e.g., .example.com) to override all subdomains, or use a SAN certificate to list all potentially used subdomains. However, wildcard certificates themselves have certain security risks. Once the private key is leaked, attackers can impersonate any of your subdomains. Moreover, wildcard certificates typically do not support multi-level subdomains; for example, .example.com can only override a.example.com, not b.a.example.com. If your wildcard DNS records cover subdomains at any depth, HTTPS encryption becomes a serious problem. Many sites that enable wildcard DNS are forced to either abandon HTTPS altogether or frequently encounter browser warnings about certificate-domain mismatches, severely impacting user experience and security.
So, does this mean wildcard DNS is always unusable? Of course not. Proper use of wildcard DNS can greatly simplify configuration, but only if you clearly understand its behavior and potential side effects. If you do need wildcard DNS, it's recommended to combine it with the following security measures: First, implement strict access control for unknown subdomains at the server level, such as returning a 403 error or a harmless placeholder page by default. Never allow malicious subdomains to access sensitive functions. Second, limit the scope of wildcard DNS. For example, only use wildcard DNS on specific record types (such as A or AAAA records), and do not simultaneously enable wildcard DNS for other record types such as MX and TXT. Otherwise, attackers may exploit it to bypass SPF, DKIM, and other email security verifications. Third, enable the traffic analysis and attack protection features provided by your DNS provider. Many professional DNS providers can identify and block random subdomain brute-force requests, or set a QPS limit for wildcard DNS. Fourth, regularly check your DNS logs and web access logs. If you find a large number of random, irregular subdomain access requests, immediately consider whether you have been attacked and assess whether you need to disable wildcard DNS or adjust your strategy. Fifth, if you don't need to resolve every subdomain, consider using a more granular whitelist instead of wildcard DNS, such as predefining only a range of subdomains instead of allowing all possibilities.
In summary, wildcard DNS is a double-edged sword. It provides great convenience for managing batch subdomains and dynamic routing, but its "overly lenient" nature makes it easy for attackers to use as a springboard. Many inexperienced website owners, after enabling wildcard DNS, either find a large number of inexplicable spam requests on their website, or are warned by search engines that the domain contains a large number of malicious pages, or even have their entire domain blacklisted by the security community. Therefore, it is recommended to be cautious about enabling wildcard DNS before fully understanding its working principles and deploying corresponding protective measures. If you've simply set up a regular company website or personal blog and don't need multiple subdomains, then there's absolutely no need to enable wildcard DNS. Maintaining specific, limited DNS records is the safest and clearest approach. Remember, in the world of cybersecurity, allowing everything by default often creates more potential problems than explicitly denying everything.
CN
EN