If you’re running a home lab (or a development environment) – you might be running a DNS server, like bind to manage your DNS records, zones, etc, and frankly, bind does an excellent job at that. However, sometime you might find your self running a home lab with a service like Pi-Hole (to keep those pesky ads away!), and Pi-Hole is doing a pretty good job as a DNS server as well.
But – sometimes you need something a bit more complicated, like a wildcard DNS.
Wildcard DNS, for those who don’t know – is a trick to allow any kind of host name – to have a specific same IP as it’s DNS name. For example, if my domain is hetz.com and my IP is 18.104.22.168, the record lab.hetz.com will also have the same IP: 22.214.171.124. Where do you need it? in many places where you’ll run tons of containers: Kubernetes, OpenShift, Rancher, etc..
The issue with Pi-Hole is that it’s possible to add a Wildcard DNS, but not through the GUI, only through the shell.
So, how do we add Wildcard DNS to Pi-Hole on our homelab? follow these steps:
- Login to your pi-hole and go to /etc/dnsmasq.d/
- Create a new file, lets call it 02-my-wildcard-dns.conf
- Edit the file, and add a line like this:
- Save the file, and exit the editor
- Run the command: service pihole-FTL restart
That’s it! You can check using commands like nslookup (on Windows) or dig (FreeBSD, Linux, Mac) that it works. For example: dig -short mydomain.lab @pi-hole-IP (replace the pi-hole-IP with your pi-hole IP).