Shell Script to Update custom.list

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(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

rm custom.list.a
rm custom.list.b


No need for scripting this:

If you enable Pi-hole's DHCP server, Pi-hole's embedded pihole-FTL -a tailored version of dnsmasq- will automatically inject the appropriate DNS records for a hostname that a client requests during a sucessful DHCP lease negotiation.
Note that upon switching to Pi-hole's DHCP server, a client may hold on to its existing lease until it expires, so it may take a while before it registers a DHCP lease with Pi-hole'S DHCP server.
You may force a client to do so by dis- and reconnecting it from your network, e.g. by switching wifi on and off on a smartphone, or by power-cycling a client device.

If Pi-hole isn't your DHCP server, you may use Pi-hole's Conditional Forwarding to have your router/DHCP/DNS server handle specific local name resolution.

I'm already using pihole as my DHCP (and) DNS server. I haven't been able to ping hosts that get a DHCP reservation. Is there a setting that I'm overlooking?

No, Pi-hole provides those DNS records for client-supplied hostnames automatically - but:

ping isn't an adequate tool to analyse DNS issues, as it employs other means to resolve hostnames in addition to DNS.

Could you share the exact ping command?
And please supply a sample result for an nslookup for the same local hostname.