Categories
SysOps

How to manage custom DNS records on a Pi-hole instance

Use dnsmasq directly to manage custom DNS records on a Pi-hole instance.

The goal is to automate the process using Ansible/Chef/Puppet, so it can be managed independently.

Simply define additional dnsmasq settings.

dietpi@DietPi:~$ cat <<EOF | sudo tee /etc/dnsmasq.d/99-self-managed.conf
address=/datanode1.example.com/192.168.8.10
address=/datanode2.example.com/192.168.8.11
address=/datanode3.example.com/192.168.8.12

txt-record=_location.datanode1.example.com,red
txt-record=_location.datanode2.example.com,blue
txt-record=_location.datanode3.example.com,red
EOF

Use /etc/hosts as a workaround to assign multiple IP address to a single DNS entry.

dietpi@DietPi:~$ cat <<EOF | sudo tee -a /etc/hosts
192.168.8.10 datanode.hosts
192.168.8.11 datanode.hosts
192.168.8.12 datanode.hosts
EOF

Restart dnsmasq service.

dietpi@DietPi:~$ pihole restartdns
  [✓] Restarting DNS server

Inspect DNS entries.

dietpi@DietPi:~$ dig +short datanode.hosts @127.0.0.1
192.168.8.11
192.168.8.12
192.168.8.10
dietpi@DietPi:~$ dig +short datanode2.example.com @127.0.0.1
192.168.8.11
dietpi@DietPi:~$ dig +short _location.datanode2.example.com @127.0.0.1 TXT
"blue"

Now you know to independently manage custom DNS records on a Pi-hole instance.