Wildcard DNS in Pihole

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 1.2.3.4, the record lab.hetz.com will also have the same IP: 1.2.3.4. 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:

  1. Login to your pi-hole and go to /etc/dnsmasq.d/
  2. Create a new file, lets call it 02-my-wildcard-dns.conf
  3. Edit the file, and add a line like this:
    address=/mydomain.lab/192.168.1.20
  4. Save the file, and exit the editor
  5. 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).

Enjoy 馃檪

4 comments

  1. This was perfect! I knew it was possible, but couldn’t get the wildcard working via the WebGUI. Now I am off to setup internal SSL certs!!

  2. I have pihole running in a k3s cluster and adapted this to a config map:


    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: pihole-wildcard-dns
    data:
    02-my-wildcard-dns.conf: |
    address=/.fruit.lab/172.0.0.1

Leave a comment

Your email address will not be published. Required fields are marked *