Trouble using Pihole to resolve local hostnames


#1

Hello All,

I have been using Pihole for quite some time now and for its ad-blocking purposes its been working great. I wanted to set up local DNS forwarding on the Pihole so that my devices could reach each other by hostname. I followed this thread.

What I did first was in the Pihole’s host file at \etc\hosts I added the following entries:

  • 192.168.1.1 router router.local
  • 192.168.1.4 pihole pihole.local (PiHole server)
  • 192.168.1.6 xxPC xxPC.local (main workstation)
  • 192.168.1.9 rome rome.local (Windows AD Server)
  • 192.168.1.10 troy troy.local (FreeNAS Fileserver)

Adding those entries allowed me to resolve the IP’s from the Hostnames on the PiHole only.

So I then as stated in the linked thread I went and added some entries to \etc\pihole\gravity.list:

  • 192.168.1.1 router.local
  • 192.168.1.4 pihole.local
  • 192.168.1.6 xxPC.local
  • 192.168.1.9 rome.local
  • 192.168.1.10 troy.local

I then restarted dnsmasq with sudo service dnsmasq restart and tried to resolve the IP on my main workstation. Couldn’t resolve host.

I know I can add the entries to each individual hosts files and they will all work perfectly, but that is not a good solution as every time I add a new server or device I would have to add a new entry to every device.

Does anyone see what I did wrong?

Thanks for any help


#2

Well, this is exactly how the Internet started! But just like you, the elders of the Internet realized at some point that updating the hosts file ever and ever again with an ever growing Internet wasn’t going to work anymore. As a consequence, they invented the DNS service.

Do you use the Pi-hole DHCP server? It would resolve this issue immediately for you.

However, I cannot reproduce the issue you are seeing:

  1. I checked that dnsmasq is reading the /etc/hosts file:
pi@raspberrypi:~ $ grep 'hosts' /var/log/pihole.log
Mar 12 01:59:25 dnsmasq[19609]: read /etc/hosts - 6 addresses
  1. I added 192.168.123.45 something.local to the /etc/hosts file on my Pi-hole
  2. I restarted dnsmasq using sudo service dnsmasq restart
  3. I verified that dnsmasq reported one entry in addition:
pi@raspberrypi:~ $ grep 'hosts' /var/log/pihole.log
[...]
Mar 12 19:03:37 dnsmasq[9800]: read /etc/hosts - 7 addresses
  1. I queried the domain something.local on the Pi-hole itself and it worked :white_check_mark:
pi@raspberrypi:~ $ dig something.local +short
192.168.123.45
  1. I queried the very same host name on a different device and that worked as well :white_check_mark:
me@desktop:~ $ dig something.local +short
192.168.123.45
  1. I confirmed in /var/log/pihole.log that there was nothing unusual:
pi@raspberrypi:~ $ less /var/log/pihole.log
[...]
Mar 12 19:04:02 dnsmasq[9800]: query[A] something.local from 127.0.0.1
Mar 12 19:04:02 dnsmasq[9800]: /etc/hosts something.local is 192.168.123.45
[...]
Mar 12 19:04:09 dnsmasq[9800]: query[A] something.local from 192.168.2.201
Mar 12 19:04:09 dnsmasq[9800]: /etc/hosts something.local is 192.168.123.45
[...]

#3

Hmm. For some reason I can now too. I just changed my router settings around because I am adding a new server.

I have not looked into DHCP from the Pi, wouldn’t that make my router mostly useless?


#4

The router would still act as the gateway, among other functions besides DHCP.


#5

Yeah, most importantly it will still provide your firewall and NAT (separating internal network from the Internet).


#6

Hey Mcat12,

I’m not sure where the issue is but from my Windows workstation I can ping pihole.local it resolves its ip and gets an answer. but if I try going to pihole.local/admin which should resolve to 192.168.1.4/admin it doesn’t work but if I go to 192.168.1.4 i can successfully access the interface.

would you be able to tell me in what way DHCP on the Pi would be better than DHCP on my router?


#7

The web interface only shows up for specific domains (pi.hole, the ip, etc) because we don’t want an ad to access the web interface (something like doubleclick.com/admin).

Using DHCP on the Pi would automatically have clients use Pi-hole as their DNS server. Some routers have issues with using local servers as DNS servers, or add in an unwanted hardcoded DNS server. Additionally, all your device’s hostnames will be available to clients in both the original and “.local” form (the latter is customizable).


#8

Ok that sounds great, but it still leaves me with two questions, in the web interface I see an option to turn it on but not to assign static ips, is it possible to assign static ips through the dnsmasq files?

Also do I have to configure the clients to use my pi as DHCP or how does it know to ask my pi for an IP now and not the router?


#9

Once you turn it on, a new dropdown menu (DHCP leases) will show up. It is not shown if the DHCP server is inactive, as it makes no sense without a running DHCP server. In this menu you will be able to specify static addresses. You can also do it via config files, if you want.

The clients will ask for an address when they connect to the network and the DHCP server will answer. Hence, they do not need to know where the DHCP server will be sitting. However it is of critical importance, that you have only one DHCP server at a time running on your network, because otherwise it is not clear which DHCP server will answer wirst and you might end up with a messed up network that works only half way.


#10

@DL6ER

IGNORE BELOW: I typed everything in manually and it didn’t work, erased that entry and then used the interface to automatically fill the info in and it worked fine.

So I enabled it on the Pi and disabled DHCP in my router settings. For the pi the DHCP range is .201 - .251

I want to assign static IPs out of that range (servers: .2-.10, workstations: .11-.20, etc), but when I set a static Ip for my workstation I double checked the mac, told it to set it to .11 and put in the hostname, but my computer still has a .235 ip.

I ran ipconfig /renew and it kept the same IP, is there something I did wrong?


#11

I’m not sure what you want to tell me… shall I ignore your entire post?


#12

I think his message is that it worked : )[quote=“bresser71, post:10, topic:2163”]
I typed everything in manually and it didn’t work, erased that entry and then used the interface to automatically fill the info in and it worked fine.
[/quote]


#13

I’ve found that pointing my PiHole to use the PDC’s DNS as a secondary DNS source to work like a charm.