How do I show hostnames instead of IP addresses in the dashboard?

Is there another way of doing this without having to edit my /etc/hosts file?

I'm able to see the local hostnames on my system using the mdns-scan command, and resolve them to IP addresses using the avahi-resolve-host-name commands, is it possible to somehow get Pihole to do this?

@dev_rath That link isn't working - is the script still available?

Looks like the script is still available on archive.org: Pihole with a view – AQuriousMind – Comics for the Curious

I honestly don't get why pi-hole can't just automate the hostname discovery. I was using pfsense with pfblockerng and it was working just fine. I also miss the posibility to whitelist all subdomains from a domain

Its not done through discovery.
The clients hostname is advertised to the DHCP servers during the DHCP renewal process.
Below client of mine is configured like below to advertise its hostname:

xbian@avr ~ $ cat /etc/dhcp/dhclient.conf
[..]
send host-name = gethostname();
[..]

So initially, only the DHCP server knows of these hostnames.

Pi-Hole V5.0 has the capability for wildcard whitelisting.

I though there was a script that can do that.

Dont need to script anything.
If the client acquires an IP through the router DHCP, you router gets to know its hostname and creates a "PTR" DNS record for it.
In below example, on a client with IP 10.0.0.9, Pi-hole does DHCP for my network:

xbian@avr ~ $ hostname -I
10.0.0.9

xbian@avr ~ $ dig +short @pi.hole ptr 9.0.0.10.in-addr.arpa
avr.dehakkelaar.nl.

EDIT: probably below is easier to understand:

xbian@avr ~ $ dig +short @pi.hole -x 10.0.0.9
avr.dehakkelaar.nl.
1 Like

Hello. I have pi-hole 5 on a raspberry pi, with dhcp from my router. I only see one client in pi-hole, just the router's IP. I edited etc/hosts adding IP and hostname from other machine on the LAN, but nothing happens. Still only one client, router IP. Any sugestions?

Change to setting in your router do assign pihole's IP as DNS-server via DHCP to clients in LAN.

Disable the 'DNS Relay' mode on the router.

It would be cool to use hw-address to assign aliases to devices and ignore hostnames altogether, ip adresses could change and I do not control all devices setups.

assigning aliases to hw-adresses would be a simple and effective solution that does not need any permissions

line 19 causes the script to fail:

from scapy.all import *

what is scapy.all , why? where?.... i'm lost on this line.

It's a networking tool written in Python. It's being imported into this script and used to listen for, and decode, DHCP traffic on your network. Then the script uses that info to update your hosts file and look up the device vendors on the external third-party Fingerbank service. It's failing because you need to install Scapy first, as well as some other prep which the script comments mention.

The script is 3.5 years old and Pi-hole has changed quite a lot since then, with new features and newer ways of doing things. Linux has also undergone many changes. It may not be a valid assumption today that changing the standard hosts file is the way to do what this script was written to do back then. It also uses this external Fingerbank service to identify your devices, and that service has its own Privacy Policy to consider.

I would advise against using the script until you have asked yourself what you are trying to achieve, and then looked at what Pi-hole today can provide natively on a current supported distro like Raspberry Pi OS Bullseye. For example Pi-hole's Network overview in Tools, which appeared a few months after this script, gives a very nice overview of all the devices visible on your network, with their hostnames, IPs, MAC addresses, vendor names and how recent they are.

1 Like

tyvm for advice, but yes I ditched the script quickly. I don't want my pi reliant on Fingerbank. I just edited the hosts file using suggested commands above: sudo nano /etc/hosts , then a pihole restartdns
I copied in IPs and device names to the hosts file from my router, after setting them permanent in router's DHCP, or just made up device names for those that lacked them like wife's iPhones and iPads ;p

Sorry script fans, it wasn't very elegant or automated, but it worked.

This OS Bullseye you mention is interesting, tho, but I don't see anything in the pihole web admin interface about network overview or see my hostnames (unless they're one's i've manually added to the hosts file), but will look further.

Please update this FAQ entry and mention as another alternative to use the conditional forwarding setting.

I found this FAQ and thought that's it's only option to manage the issue via /etc/hosts or to use the PiHole DNS. Fortunately somebody pointed out I instead can use the DNS of my router when I configure conditional forwarding :slight_smile:

What about situation when I have pihole as Container on Mikrotik router? :wink:
How to see/define client names on pihole?

Thanks in advance

It depends on what kind of network driver you are using.

For macvlan (assuming you are using docker containers) it should be the same as for a physical host because pihole will have an IP in your local network. However from the pihole container there should be a route to the routers IP.

I think the conditional forwarding option should also work if the pihole is in a different subnet as you need to define the local subnet, domain and you router (DHCP server) IP.
What could be a problem is if you don't have a working route from the pihole container to the DHCP server IP (which is not trivial in case of macvlan for example).

I also wish there was an easier way to do this, editing /etc/hosts every time is going to get tiresome quickly, not to mention remembering to delete the entries too.. Brutal.. I am using OPNsense for the DHCP already

I have also setup conditional forwarding as recommended, but still no hostnames were shown.

Then I noticed my modem showing up in the dashboard of pihole as upstream server, it seemed pihole did forward some requests. So I have checked the log of queries sent to my modem (just clicking on the name/ip):

Type	Domain					Client			Status								Reply
PTR	  1.0.168.192.in-addr.arpa  192.168.0.120	OK (answered by getmodem.home#53)	DOMAIN (3.0ms)
PTR	136.0.168.192.in-addr.arpa	192.168.0.108	OK (answered by getmodem.home#53)	NXDOMAIN (16.3ms)
PTR	132.0.168.192.in-addr.arpa	192.168.0.108	OK (answered by getmodem.home#53)	NXDOMAIN (17.2ms)
PTR	131.0.168.192.in-addr.arpa	192.168.0.108	OK (answered by getmodem.home#53)	NXDOMAIN (18.8ms)
PTR	128.0.168.192.in-addr.arpa	192.168.0.108	OK (answered by getmodem.home#53)	NXDOMAIN (19.7ms)
PTR	121.0.168.192.in-addr.arpa	192.168.0.108	OK (answered by getmodem.home#53)	NXDOMAIN (20.4ms)
PTR	115.0.168.192.in-addr.arpa	192.168.0.108	OK (answered by getmodem.home#53)	NXDOMAIN (21.9ms)

As you can see from the log the modem only resolves it's own IP with reverse look-up, but not the other hosts. The same can be verified using dig e.g.:
dig -x 192.168.0.121 @192.168.0.1

So also check reverse look-ups with your modems/DHCP servers before blaming only pihole.. :slight_smile: