Please forgive me if this topic has been discussed before. I did a quick and dirty search. If it has, please point me to the post.
I define all my hostnames on my LAN in the /etc/hosts file on my local DNS Server (pi-hole) for both static and dynamic IP addresses.
However, whenever the DHCP lease expires for a device and a new IP address is assigned, the /etc/hosts entry is outdated and the device is now unreachable by hostname.
Can someone please advise me on how I can manage the hostnames for devices assigned IP addresses dynamically without having to constantly update the /etc/hosts file?
Use a DHCP server that uses a deterministic way to assign IPs to clients.
In that way the same device should always get the same IP and the the entries in /etc/hosts should stay the same.
One possible solution is to use pihole as DHCP server as well (next to DNS server). Pihole is a deterministic DHCP server.
Add: instead of manually editing /etc/hosts you could manage your local DNS records via Pihole's web interface ("Local DNS Records"). It uses the file /etc/pihole/custom.list in the background.
There are a few things to consider for deterministic DHCP servers, and your router may not allow to replace its DHCP server. (click for more)
Note that using a deterministic DHCP server works well with partially populated DHCP ranges - as a best-effort approach, it cannot guarantee exclusive IP address usage with client counts nearing or exceeding the range capacity limit.
While this would be trivial to mitigate in most cases by enlarging the pool, your router may impose arbritray limits to what you actually can configure.
Also, it may not always have the desired effect e.g. when using virtualised network interfaces or environments, as those may register DHCP with a different client id instead of the usual MAC address on each start.
For cases like this, you'd had to configure a static IP address on device rather than in your router.
If switching DHCP servers is not an option for you, see if your router would support configuration of DHCP lease reservations, also labeled as fixed IP address assignment or similar.
Your router would then reserve a specific IPv4 address for a specific device's network interface.