How to copy Static DHCP leases to Local DNS Records

Just a simple thing I figured out today. Let's say you've gone to the trouble of chasing down all the MAC addresses on your network and assigned them static DHCP leases, putting the desired DNS hostname in the Hostname field, like I just did. Now you want Local DNS Records for each of these IPv4 address / Hostname pairs. Just SSH to your pi-hole and run this.

cut -d, -f2,3 /etc/dnsmasq.d/04-pihole-static-dhcp.conf | sed 's/,/ /'

You can merge that any way you like into /etc/pihole/custom.list, but I like to just append it and purge any duplicates that came up.

sudo bash
cp /etc/pihole/custom.list /etc/pihole/custom.list.tmp
cut -d, -f2,3 /etc/dnsmasq.d/04-pihole-static-dhcp.conf | sed 's/,/ /' >> /etc/pihole/custom.list.tmp
sort /etc/pihole/custom.list.tmp | uniq > /etc/pihole/custom.list
rm /etc/pihole/custom.list.tmp

That works great for me.

1 Like