When working with Host Named Site Collections (HNSC) you have to keep on top of the DNS records. SharePoint can only do so much, after all. Since your HNSCs all have different host names, that is the point after all, they each need to be resolvable in DNS. If you’re only going to have a handful of HNSCs it’s easy to just drop into your DNS server and create them. It gets a little trickier when you add HNSCs down the road. You tend to forget to create the DNS entries. It becomes a lot trickier if you create a lot of HNSCs and if the SharePoint team doesn’t control DNS. Then it turns into constant tickets, the network team taking their sweet time, much swearing, and users have to wait for the beloved SharePoint site to come online. What if there was a way to prevent all that needless pain and suffering? I have the solution, wildcard DNS records (you probably guessed that from the title of the blog post).
We’re all familiar with the common types of DNS records, like A records and CNAME records. In most cases these records resolve a single address. For instance, the A record for www.toddklindt.com points to the IP address of my web server, 127.0.0.1. However, it is possible to create a wildcard A record. This record provides a default value for DNS records that aren’t defined. In the context of HNSCs you would create a wildcard DNS A record that points to your SharePoint farm. Then when you create a HNSC with the URL https://foo2.contoso.com it will resolve to the SharePoint farm and work without having to bother those lazy gits on the network team.
To create a wildcard DNS record, create a record for *. Here’s how it looks in the DNS Manager in Windows 2012 R2:
Here’s how it looks in glorious PowerShell:
Add-DnsServerResourceRecordA -ZoneName odfbdemo.com -Name "*" -IPv4Address "172.27.1.2"
Here’s what it looks like when it’s created correctly:
Again, this doesn’t resolve every host in the odfbdemo.com DNS zone to 172.27.1.2, only the hosts that don’t already have an A or CNAME record.
While there are other uses for wildcard DNS records, they are quite handy for HNSCs in SharePoint.