Problems resolving local hostnames

Hi! Thanks for Pi-Hole! I setup my Pi-Hole yesterday. Seems to do it's job just fine. However, I have two issues related to resolving local hostnames.

  1. On the Pi-Hole server itself, I used to be able to resolve local computers using the ".lan" pseudo-TLD. I don't know much about this, but I stumbled upon it when everything else was failing in my mixed Win/Mac/Linux. How is this supposed to work?

  2. On other computers in the network, I can no longer resolve the name of the Pi-Hole server. I first noticed this about a day after the install. I had a browser tab open to http://xxxpi.lan/admin (replace xxxpi with my actual Pi's hostname, and I was uncertain whether it was auto-refreshing, so I hit Refresh. Chrome told me it couldn't resolve the name. Then I tried on the command line with ping, and tried on other hosts, but it no longer works. Is this a question of the Pi-Hole not registering with my router's "DNS" any more?? Note that I've had this Pi setup for quite some time, and it has done other things, so I need to be able to resolve the name.

Thanks for any help!

Can you look in the file /etc/pihole/gravity.list to see if your hostname is in the first line? We load the hostname stored in /etc/hostname to the top of the list so that you can continue to use it after changing your dns server. Also, try loading it without the .lan ending.

Hi! Thanks for the response; sorry it has taken a while to get back to you.

Yes indeed, first two entries are tvpi and pi.hole (btw, shouldn't that be pi-hole?? isn't the period meaningful in dns?)

Here's what I can tell you. The tvpi.lan name used to work on Win, Mac, and Linux. Currently, it resolves on none. tvpi by itself also resolves on none as well.

And when I ssh to tvpi (by IP address now!), it can't resolve any local hostnames, with or without the .lan

Might be interesting to note, on my pi-hole server:

pi@tvpi:~ $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 127.0.0.1

And on another pi:

pi@campi:~ $ cat /etc/resolv.conf
# Generated by resolvconf
domain lan
nameserver 10.10.10.254

The .254 is my router, and of course it is configured to use tvpi (10.10.10.119) only for DNS.

Dnsmasq looks at /etc/hosts for local domain hostnames, you will need to set them up there. You will want to include both the FQDN and the short name.

Example /etc/hosts (use whatever 'fake' domain you want in place of home.lan--Macs/bonjour/mdns uses .local, not sure how Windows handles it these days, so ymmv if you use .local)

10.10.10.254   router router.home.lan
10.10.10.X   tvpi tvpi.home.lan
10.10.10.X   campi campi.home.lan
...

You cannot configure dnsmasq to look at the router's host table--it's not designed to do that.

Also make sure your local domain is set in the dnsmasq configuration file, /etc/dnsmasq.d/01-pihole.conf:

domain=home.lan
expand-hosts
local=/home.lan/

More details here: http://superuser.com/questions/835189/using-dnsmasq-to-address-machines-by-name-and-resolve-external-hostnames
https://www.linux.com/learn/dnsmasq-easy-lan-name-services

As for your resolv.conf files, the 'tvpi' pi-hole system is set up to use the local dnsmasq (e.g. loopback address, 127.0.0.1) to resolve hostnames. If you ran the installation script and didn't over-ride the default settings, it now has a static IP and won't get any DHCP settings from the router. So having 127.0.0.1 is by design to prevent name resolution issues due to forwards going nowhere.

The other system, 'campi', is still receiving it's IP via DHCP from the router, so it's resolv.conf is set by the router. In my experience, most modern home routers always set themselves to the be the DNS server via DHCP, and short of installing 3rd party firmware, you can't over-ride that behavior.

If you are feeling adventurous, you could configure dnsmasq to handle DHCP and cut the router out of the equation entirely.

HTH--
=V=

1 Like

So, I have added a line to my /etc/hosts file:

10.10.10.119 tvpi.lan tvpi.local tvpi

But still, neither tvpi.lan nor tvpi resolve from other clients. tvpi.local resolves, from my mac and Linux boxes, but I imagine that's using a different mechanism (Bonjour, as you say).

OTOH, tvpi and tvpi.lan do resolve on tvpi itself.

So, I'm still a bit confused. Computers on the network are configured to talk to the router for DNS; the router is configured to use the pi-hole; and the pi-hole uses OpenDNS. Definitely works for the internet at large, but the local stuff is problematic.

Thanks for any further advice.

You would need to add entries to /etc/pihole/gravity.list in the format of IP-Address Name for your network to have those names associated with IP addresses. Or you could add all the associations you want to the Pi's hosts file and then copy those to all the computers you want them on.

@velociraptor thanks
Like the OP, I could only reach my pi-hole by just the hostname (from /etc/hostname), or pi.hole. I wanted to address the pihole with hostname.lan where "lan" is the domain configured in the router.
I added this to /etc/dnsmasq.d/01-pihole.conf

domain=lan
local=/lan/

The local setting fixed another problem which was that pi-hole was forwarding many ***.lan to the external DNS server. Perfect.

How important is it that /etc/pihole/gravity.list has the contents of /etc/hostname as the first line? I have the same issue (my pihole server's system name not being found when nslookup) and the first line in my /etc/pihole/gravity.list has:
192.168.254.2 0.0.0.0
instead of
192.168.254.2 mypiholesystem.home
as this post mentions?

The hostname will be contained in another list (/etc/pihole/local.list).

Edit: The above posts used to be accurate, but we moved the hostname and pi.hole domains to local.list since then.

/etc/pihole/local.list contains:
pi@HornPiDNS:~ $ cat /etc/pihole/local.list
192.168.254.2 HornPiDNS
192.168.254.2 pi.hole

and on HornPiDNS (which is the system that pihole runs on, does translate correctly, but the other systems do not translate hornpidns.

Try adding the hostname to /etc/hosts

I actually have it in that file.

Can you find the request for the hostname in the log? You can also run pihole -t and try to ping the domain from another computer to see if dnsmasq is not handling it correctly.

Ok, I've made some changes to the network but still having issues.
The RaspberryPi running PiHole has been hosting the DNS and has not been able to translate the name to an ip. Yesterday I setup my RaspberryPi running PiHole to also take care of DHCP.
Looking at some of the responses above I still probably have some configuration issues.

gravity.list has "192.168.254.2 0.0.0.0" as the first line.

The file /etc/resolv.conf has:

Generated by resolvconf

nameserver 127.0.0.1

Currently, /etc/hosts only has:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

/etc/dnsmasq.d/01-pihole.conf does not have the "domain=", "expand-hosts", or "local=/home.lan/" entries

Here is the output for pihole -t (hornpidns is the PiHole systems hostname, and do notice there is some configuration issue with it showing hornpidns.home.home)

^Cpi@HornPiDNS:~ $ pihole -t
[i] Press Ctrl-C to exit
19:31:27 dnsmasq[19305]: reply hornpidns.home.home is NXDOMAIN
19:31:27 dnsmasq[19305]: query[A] hornpidns.home from 192.168.254.8
19:31:27 dnsmasq[19305]: cached hornpidns.home is NXDOMAIN
19:31:27 dnsmasq[19305]: query[AAAA] hornpidns.home from 192.168.254.8
19:31:27 dnsmasq[19305]: forwarded hornpidns.home to 208.67.220.220
19:31:27 dnsmasq[19305]: reply hornpidns.home is NXDOMAIN
19:31:31 dnsmasq[19305]: query[A] HornPiDNS from 127.0.0.1
19:31:31 dnsmasq[19305]: /etc/pihole/local.list HornPiDNS is 192.168.254.2
19:31:32 dnsmasq[19305]: query[AAAA] HornPiDNS from 127.0.0.1
19:31:32 dnsmasq[19305]: cached HornPiDNS is NODATA-IPv6
19:31:36 dnsmasq[19305]: query[PTR] 2.254.168.192.in-addr.arpa from 192.168.254.8
19:31:36 dnsmasq[19305]: /etc/pihole/local.list 192.168.254.2 is HornPiDNS
19:31:36 dnsmasq[19305]: query[A] hornpidns.home.home from 192.168.254.8
19:31:36 dnsmasq[19305]: cached hornpidns.home.home is NXDOMAIN
19:31:36 dnsmasq[19305]: query[AAAA] hornpidns.home.home from 192.168.254.8
19:31:36 dnsmasq[19305]: cached hornpidns.home.home is NXDOMAIN
19:31:37 dnsmasq[19305]: query[A] hornpidns.home from 192.168.254.8
19:31:37 dnsmasq[19305]: cached hornpidns.home is NXDOMAIN
19:31:37 dnsmasq[19305]: query[AAAA] hornpidns.home from 192.168.254.8
19:31:37 dnsmasq[19305]: cached hornpidns.home is NXDOMAIN
19:31:47 dnsmasq[19305]: query[A] wpad.home from 192.168.254.8
19:31:47 dnsmasq[19305]: cached wpad.home is NXDOMAIN

Any help will be greatly appreciated.

Run pihole -d for a debug token. Did you set the local domain in the DHCP settings when you were setting it up? The .home.home queries are coming from an incorrectly configured device.