Pihole DHCP writes to hosts file as well


#1

when a static lease is set in the DHCP portion of the admin page should be possible to write the lease to /etc/hosts as well allowing for simple adding of hostnames


#2

You can already set hostnames with the static leases, or am I misinterpreting your request?


#3

Will test when I get home but to my knowledge this did not bring the hostnames into the webgui instead of ip’s this feature request was based off of a troubleshooting thread from Reddit that I will link when not on mobile


#4

Make sure you disable your router’s DHCP if you use Pi-hole’s otherwise clients might get an address from one or the other.


#5

I do not have this issue personally I just edit the hosts file myself


#6

The hosts file is intended to be used by the own host itself and not to be shared by other hosts.
The hosts file may contain entries like for example below one:

127.0.1.1 pihole.your.domain

Lets assume a second system tries to connect to “pihole.your.domain” reading from that same hosts file, it gets IP address “127.0.1.1” returned via DNS.
That localhost IP address will make the other host try to connect to itself on the loopback interface instead of connecting to the intended host “pihole.your.domain”.

Pi-Hole does some trickery so the hosts file can be read by dnsmasq but this file was never intended to be used by the other hosts on the network.
See the hosts file more as a personalized map of the network from the own hosts point of view.

More complex systems have multiple hosts entries that would make no sense for the other hosts on the network when trying to resolve from host to host.
Below an example of two different hosts files for if you might want to cluster the Pi-Hole services:

# /etc/hosts file for "ph-node1.your.domain"
10.0.0.10      ph-cluster.your.domain
127.0.0.1      ph-node1.your.domain
10.0.0.12      ph-node2.your domain
127.0.0.1      ph1-heartbeat.your.domain
192.168.0.2    ph2-heartbeat.your.domain

# /etc/hosts file for "ph-node2.your.domain"
10.0.0.10      ph-cluster.your.domain
10.0.0.11      ph-node1.your.domain
127.0.0.1      ph-node2.your domain
192.168.0.1    ph1-heartbeat.your.domain
127.0.0.1      ph2-heartbeat.your.domain