I have searched for a way to have pihole update DNS when it hands out a DHCP reservation. I don't think it's possible. If it is, please someone tell me how.
In lieu of a built in feature, I wrote a shell script that manipulates /etc/pihole/custom.list and adds the entries from dhcp.leases to the file.
Here's the code:
#updates the custom.list (local DNS entries) with items from dhcp.leases
#then sorts the list and copys the file to the correct location
pushd .
#make a copy of the current custom defined DNS entries
cp /etc/pihole/custom.list /tmp/custom.list.a
cd /tmp
#keep entries from the current custom list where the last octet of the IP is less than 40
#my convention for my home network is to have all server IP addresses in the range of x.x.x.1 - x.x.x.39
cat custom.list.a | awk '{
split($0,a,".")
b=a[4]
split(b,c," ")
#print c[1]
if (c[1] < 40)
print $1 " " $2
}' > custom.list.b
#now pull in the DHCP leases from the DHCP server
#the file has to be parsed to get the IP and hostname in that order
#if the hostname isn't given to the DHCP server, and the table contains '*' for the hostname, I skip it.
cat /etc/pihole/dhcp.leases | awk '{
if ($4 != "*")
print $3 " " $4
}' >> custom.list.b
#sort the list by IP address
cat custom.list.b | sort -t . -k 3,3n -k 4,4n > custom.list
#copy the updated list to pihole
sudo cp custom.list /etc/pihole/custom.list
#cleanup
rm custom.list.a
rm custom.list.b
popd