34

I asked my hoster to add three subdomains all pointing to the IP of the A record. It seems he simply added a wildcard DNS record because any random subdomain resolves to my IP now. This is OK for me from a technical point of view, since there are no subdomains pointing anywhere else. Then again I don't like him not doing what I asked for. And so I wonder whether there are other reasons to tell him to change that. Are there any?

The only negative I found is that someone could link to my site using http://i.dont.like.your.website.mywebsite.tld.

2
  • 13
    Someone could link to your server using "i.dont.like.your.website.mywebsite.tld" but your server shouldn't respond unless it's configured to respond to it (via hostheaders or virtualhosts).
    – joeqwerty
    Mar 1, 2013 at 0:36
  • 8
    In some cases wildcards can be required. For instance, multi-tenant webapps like Wordpress can be configured to automatically spawn new instances using sub-domains -- e.g. site1.blog.example.com, site2.blog.example.com -- with the wildcard in place for *.blog.example.com, you don't need to go configure each of these individually.
    – jscott
    Mar 2, 2013 at 1:51

10 Answers 10

25

If you ever put a computer in that domain, you will get bizarre DNS failures, where when you attempt to visit some random site on the Internet, you arrive at yours instead.

Consider: You own the domain example.com. You set up your workstation and name it. ... let's say, yukon.example.com. Now you will notice in its /etc/resolv.conf it has the line:

search example.com

This is convenient because it means you can do hostname lookups for, e.g. www which will then search for www.example.com automatically for you. But it has a dark side: If you visit, say, Google, then it will search for www.google.com.example.com, and if you have wildcard DNS, then that will resolve to your site, and instead of reaching Google you will wind up on your own site.

This applies equally to the server on which you're running your web site! If it ever has to call external services, then the hostname lookups can fail in the same way. So api.twitter.com for example suddenly becomes api.twitter.com.example.com, routes directly back to your site, and of course fails.

This is why I never use wildcard DNS.

13
  • 3
    @ChrisLively Blame modern Linux systems for being "helpful" and adding it. BTW, using ".local" really is bad practice, and not just in Windows environments. Mar 1, 2013 at 2:14
  • 7
    I actually blogged about this in regards to a Windows environment. Not to mention that at least three groups have bid on the .local TLD now that ICANN is selling them to anyone with a substantial enough wallet. .local isn't reserved and shouldn't be used. Doing so violates RFCs and isn't necessary at all. Best practice is to use a delegated third-level subdomain for internal resources like internal.company.com. Just because you see something a lot doesn't make it right.
    – MDMarra
    Mar 1, 2013 at 2:23
  • 2
    Could you please point me to the section of RFC 2606 that reserves .local? I've read this RFC at least a dozen times with people that use it in this argument and I can tell you with certainty that it's not there.
    – MDMarra
    Mar 1, 2013 at 2:32
  • 3
    @Zypher It actually was never recommended by Microsoft (that's debunked in my blog post too. Go read it, it's a good one), but the fact that SBS shipped using .local by default really made MS look like a mess in that regard. SBS shipped with that configuration because it was meant for non-tech customers with low technical knowledge. It was the path of least resistance, but the actual AD docs recommend a third-level subdomain all the way back in the W2K era.
    – MDMarra
    Mar 1, 2013 at 2:35
  • 3
    Oh, and in a few years it's going to be very difficult to get certificates for .local which means UCC/SAN certs for Lync/Exchange will have to be signed by an internal CA, making it painful if you have external non-domain joined users.
    – MDMarra
    Mar 1, 2013 at 3:03
19

Is a wildcard DNS record bad practice?

Personally, I don't like it. Especially when there are machines in that domain. Typos go unchecked, errors are less obvious... but there's nothing fundamentally wrong with it.

The only negative I found is that someone could link to my site using http://i.dont.like.your.website.mywebsite.tld.

Have your http server redirect all such requests to the proper, canonical addresses, or not respond at all. For nginx that would be something like:

server {
    listen 80;
    server_name *.mywebsite.tld;
    return 301 $scheme://mywebsite.tld$request_uri;
    }

and then the regular

server {
    listen  80;
    server_name mywebsite.tld;
    [...]
    }
11

It's all a matter of opinion. For me it's not bad practice.

I'm creating a multi-tenant app which uses a database per tenant. It then selects the database to be used based on the subdomain.

For example milkman.example.com will use the tenant_milkman database.

Like this I have separated tables for each tenant, like, tenant_milkman.users, tenant_fisherman.users, tenant_bobs_garage.users, which in my opinion is a huge lot easier to maintain for this specific app, instead of having all users from all companies in the same table.

[edit - Michael Hampton has a good point]

That being said, if you don't have a specific reason to accept any (variable) subdomain, like I do, then you shouldn't accept them.

6
  • 6
    You have a good technical reason to use wildcard DNS. Most people don't. Jul 23, 2014 at 14:46
  • 1
    As a matter of fact, this seems highly dangerous to me - it allows you to access an arbitrary database by changing the domain name. I'd argue that this is a type of injection vulnerability. Admittedly it's not necessarily exploitable - but why take chances?
    – sleske
    Jan 6, 2017 at 11:25
  • 2
    @sleske It's not, because the user must authenticate against that subdomain (for that database). If he switches, he will need to authenticate again, as it is seen as a completely different "site". Jan 6, 2017 at 11:35
  • @PedroMoreira: Yes, that reduces the attack surface. Still, providing access to arbitrary databases seems dangerous. For example, what if there is a backup database with identical credentials, but data that was purged from the main db - this would allow anyone access who knows the name. Still, I realize security is always a tradeoff - just wanted to point out the inherent danger.
    – sleske
    Jan 6, 2017 at 11:43
  • 1
    @sleske That's why all the accessible databases are prefixed with tenant_. I made sure the application can't even connect to them. Jan 6, 2017 at 14:29
2

Another issue here is the SEO: if all *.example.com showing the same content, your website will be badly referenced, at least by Google (https://support.google.com/webmasters/answer/66359).

3
  • 2
    Both points are orthogonal. Even if all names point to the same IP, the webserver gets the name requested and can deliver completely different content. Jul 31, 2019 at 15:29
  • That's why I have precized "if all *.example.com showing the same content"... The SEO risk sounds to me to something interesting to mention. Aug 1, 2019 at 16:06
  • "The SEO risk sounds to me to something interesting to mention." Maybe but they are completely unrelated to using a wildcard or not. You can have many separate names all resolving to a single IP address without any kind of wildcards and hence having (or not) the SEO risks you speak about. The use of a wildcard does not change anything in any direction here. Aug 1, 2019 at 16:11
2

There's one rather important crucially GOOD use of wildcard DNS: to block subdomain spam via spf!

Along with whatever else is configured, it is rather important to also set up:

*.example.com.      21599   IN      TXT     "v=spf1 -all"

Why? Because without this, a spammer can and will send millions of emails using random (non-existent) subdomains spoofing your primary domain.

Real world data from 2023 (plus global research from 1 1/2 years ago)

  • There are now about 1 1/2 billion email servers have a domain that responds to a DNS query
  • About 1/3 do use/check spf in some way (I'm ignoring misconfiguration for this)
  • About 0.03% use/check DMARC and DKIM. (DMARC can block invalid subdomain email.)

So: how do we tell a billion email servers that we don't send email from miscellaneous nonexistent subdomains? With a wildcard TXT subdomain entry.

Real world data on what happens when we don't do that...

  • I have a small email server. It never sends or receives email using its own domain. It only services our other domains. ANY email sent with its domain is by definition invalid.
  • I have properly configured SPF, DKIM and DMARC for the domain. All (spam) emails from [email protected] do get blocked at the recipient end, by spf and/or DMARC.

Without wildcard TXT spf subdomain, what happens?

  • From DMARC reporting, we know the 0.03% of DMARC-capable servers block over 4200 spam emails a week (mostly from Asia). They are emails from "[email protected]" ... @clt.example.com... etc etc
  • Since that represents only 0.03% of servers at best (not all send reports!), the other 99.97% are receiving over 14 million spam emails a week on my non-existent subdomains!
  • AND, the 1/3 of servers -- about half a billion -- that have SPF... they APPROVE the emails because I don't have an spf record for every possible subdomain.
  • That's 5+ million spams a week getting through to servers that DO check spf!

By setting up wildcard TXT as shown above, those ten million spams are all blocked. Yes, the other 2/3 of servers don't block, but that's not our problem.

Data Sources:

  • RedHunt Labs, "Wave 6 Internet=Wide Study: State of SPF, DKIM and DMARC" 10 Feb, 2022
  • Real world spam capture data: DMARC reports for one of my own domains.
2
  • Wouldn't be better to use v=spf1 +mx:<BASE_DOMAIN> -all if your base domain is configured for emails? community.letsencrypt.org/t/…
    – vogdb
    Dec 4, 2023 at 14:21
  • 1
    @vogdb yes it would, but our base domain never sends email as that domain. The domain IS used to identify our various servers. So, while our *.example.com has no MX, we have other domains for which server.example.com IS the MX :)
    – MrPete
    Jan 14 at 20:52
1

I know this is an old question, however I'd like to share a real world example of where using wildcard domains can cause problems. I am however going to change the domain name and also hide the full SPF record to save embarrassment.

I was helping someone who was having issues with DMARC, as part of the checks I always look up the DMARC record with DIG

;; ANSWER SECTION:
_dmarc.somedomain.com. 21599 IN      CNAME   somedomain.com.
somedomain.com.      21599   IN      TXT     "v=spf1 <rest of spf record> -all"

I also got the same result when looking for their DKIM record.

Consequently emails sent from this domain will get a DKIM fail as the DKIM module will try parsing the SPF record for a DKIM key and fail, and will also get a Permerror for DMARC for the same reason.

Wildcard domains might seem like a good idea but set up wrongly they can cause all sorts of issues.

0

This is really a bad idea, suppose if you want to host one subdomain a.company.com in one web server, and b.company.com in another web server, may be another ISP. What you will do ?. So wildcard DNS is not an option, it should be precise, create A record for each sub domain and points to relevant IP. Chances are there to move your web server from one ISP to another ISP, in this case what will you do ?

2
  • not gonna work if you want to allow thousands of people to sign up w/o human intervention.
    – Ajax
    Aug 18, 2021 at 7:29
  • and adding dns on demand would be slow. wildcard means no latency to propagate DNS if you wanna spin up a new namespace.
    – Ajax
    Aug 18, 2021 at 7:30
0

Using wildcard DNS record is bad practice only if you don't actually serve wildcard service. In addition, some ancient programs may have greater change to fail DNS query.

Other answers have already provided lots of examples where you try to mix wildcard domain with static names and there're potential pitfalls for those cases. Those cases are actually cases where the original intent wasn't to serve wildcard service and as a result, some static usage accidentally slipped to wrong static service (instead of slipping to a wildcard service that can correctly handle any wildcard or it's not a true wildcard service).

TL;DR: wildcard DNS is good for wildcard services, but it's bad practice to use wildcard DNS for static services because any errors are harder to diagnose.

-2

I think the best reason not to have a wildcard DNS record in the first place is to avoid giving away your server IP address to a potential attacker and reduce the exposition to DDOS attacks. This is also recommended setup by Cloudflare: https://blog.cloudflare.com/ddos-prevention-protecting-the-origin/

3
  • 2
    Using wildcard domains does not change exposure to such attacks. And the link does not support your incorrect claims. All that link says is that Cloudflare happen to be charging a higher price for wildcard domains. That only says something about Cloudflare's business models and nothing about the practice of using wildcard domains.
    – kasperd
    Jan 9, 2017 at 0:23
  • 1
    If you use wildcard dns with cloudflare since it doesn't go through cloudflare (unless you pay enterprise, most don't) anyone can ping any a made up subdomain and find your real IP. Without wildcard they can't. that's all there is to it. Jan 9, 2017 at 13:26
  • Yes in case of such service, they may charge you more for wildcard protection. Although this question isn't about those types of services its about wildcarding dns and whether it should be done or not under normal situations. Sep 25, 2019 at 20:55
-3

Is a wildcard DNS record bad practice?

No, and contrary to others I believe it is good practice.

Most internet users fat finger a DNS name at some point. They will type ww.mycompany.com or wwe.mycompany.com What would you rather happen an "oops we couldn't find that site" or for them to pull up your primary home page? More often than not having them pull up your primary home page is preferable. Which is what a LOT of people do.

Even if someone put a link to i.dont.like.your.website.whatever.com it would still pull up your home page, which is actually what you want. After all, they can't make that i.dont.... site go to their server, you still control the DNS routing so it goes to yours.

1
  • 6
    The problem I have with this reasoning is that 1. it breaks error handling, 2. it's entirely www-centric while your wildcard records will affect other protocols as well. The result being that you've broken error handling for other things where you have made no effort to patch things up. Jul 23, 2014 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .