Pi-hole - hostname resolution not working except if I edit /etc/hosts

Associate
Joined
13 Jun 2016
Posts
1,519
Location
UK
So I am currently running Pi-Hole on a Raspberry Pi. Absolutely love it and when I get my home server up and running, might move it to a Debian container. Anyway, I digress - I am not able to get IP addresses to resolve to hostnames unless I actually edit the /etc/hosts file on my Pi. I am sure there must be a more elegant way of doing it!

So this image from my Pi-Hole web interface shows what I mean. I would like the local IP addresses to show their hostnames instead:

Capture1.png


However localhost and vanguard resolve if I edit my Pi /etc/hosts file and then reboot:

Capture6.png


According to the Pi-Hole web admin GUI, I should be able to achieve what I want by using conditional forwarding, which I have tried setting up as per the below image - 192.168.1.1 is by EdgeRouter:

Capture2.png


But that doesn't work. Here are what I think are the relevant parts of my EdgeRouter setup. First is the DHCP setup - I'm using one DHCP server for eth1, called 'LAN1':

Capture3.png


I've set the domain name to be LAN1 below, with DNS1 to be my Raspberry Pi's IP address:

Capture4.png


And below you can see the static IP mappings for some of the devices:

Capture5.png


And inside the DNS wizard on my EdgeRouter I've got the various hostnames setup, as I think the names under the DHCP server configuration are just a 'simple name' and not actually the network hostname...

Capture7.png


I don't get why it doesn't work and have reached as far as I can go :( Any ideas would be much appreciated and I've put it in the open source subforum as I'm hoping I'll get more help from here :)

TIA :D
 
The only way I've managed it is via the hosts file. I run pi-hole as a DHCP server as well and all my known clients have reserved addresses so when I add a new one, I just update the hosts file as well.
 
Another way to do this is to add a new local zone into dnsmasq which Pi-Hole will then query.

Firstly you need to tell dnsmasq about this file you're going to create. Run the command:
Code:
echo "addn-hosts=/etc/pihole/lan.list" | sudo tee /etc/dnsmasq.d/02-lan.conf


That will create /etc/dnsmasq.d/02-lan.conf which contains the following:
Code:
addn-hosts=/etc/pihole/lan.list


Alternatively just use your text editor of choice and create the file.

Next you need to populate that file using the following format:
Code:
IPADDRESS  <tab>  FQDN  <tab>  HOSTNAME


Replace <tab> with tab, don't literally type <tab>

So if you take vanguard as an example, the file would look like this:
Code:
192.168.1.232  <tab>  vanguard.homedomain.com  <tab>  vanguard


Add in any other devices with a static IP and replace homedomain.com with whatever domain name you're using.

Then restart the DNS services with 'sudo pihole -g' (there's other ways, that's how I normally do it) and you should then be able to resolve vanguard in DNS. Check that with 'host vanguard' which would show the forward DNS resolution:

Code:
[root@pihole1 ~]# host vanguard
vanguard has address 192.168.1.232


Then to check the reverse DNS:

Code:
[root@pihole1 ~]# host 192.168.1.232
232.1.168.192.in-addr.arpa domain name pointer vanguard.homedomain.com.


You should then find that the charts in Pi-Hole start showing hostnames.
 
Back
Top Bottom