Running pihole breaks localhost name lookup

I am running pihole on a raspberry pi assigned to 192.168.1.250 and my router configured to use pihole as the DNS. Ads are blocked as expected for connected devices. When a new device connects to the network, it gets the DNS entry of 192.168.1.250 as expected. For example, if I look at /etc/resolv.conf on my laptop:
nameserver=192.168.1.250

Before pihole, I could ssh into other machines on my LAN by using their hostnames but after pihole, all the hostnames are missing. I believe this is due to pihole not being the DNS for the LAN. Is there a simple setting to fix this?

I can "undo" this simply by editing /etc/resolv.conf on my laptop and redefining 192.168.1.1 there but of course, doing that makes pihole's adblocking non-functional for the laptop.

You can use Pi-hole for your DHCP server, which would automatically give you the hostnames. Or you could give each device a DHCP reservation in the router and assign them hostnames via the Pi-hole's /etc/hosts file.

I'm using LEDE (based on OpenWRT) on my router + a pi-hole box on the LAN together and the setup works to:

  1. Make new DHCP clients use pihole as their DNS
  2. Block ads via pihole
  3. Allow for local LAN ssh connections or ping command via the advertised hostname of that device

Basically, the router advertises the pi-hole IP address but it uses its own DNS servers if the request is not blocked by the pi-hole box. Since the router’s DNS is the only upstream resolver of the pi-hole machine, both LAN and WAN hostname resolving is possible.

The pi-hole machine's IP is 192.168.1.250 for me...

On LEDE, all defaults are set except for:
Network>Interfaces>LAN>edit>DHCP Server>Advanced>DHCP Options: 6,192.168.1.250

On pihole:
/etc/dnsmasq.d/01-pihole.conf
addn-hosts=/etc/pihole/gravity.list
addn-hosts=/etc/pihole/local.list
addn-hosts=/etc/pihole/black.list
...
server=192.168.1.1

Any router firmware worth its salt will allow you to define a custom dnsmasq entry. As another example, on TomatoUSB:

Advanced>DHCP/DNS>Dnsmasq Custom configuration:
dhcp-option=6,192.168.1.250

Do NOT change Basic>Network>Static DNS (unless you want to use custom DNS entries).
Do NOT uncheck Advanced>DHCP/DNS>Use internal DNS.

1 Like

There are basically four options

  1. Use Pi-hole for your DHCP server (as suggested by @Mcat12)
  2. Statically assign them in /etc/hosts (as suggested by @Mcat12, too)
  3. Add your router as one of the upstream DNS servers (and untick the FQDN option on the Settings page)
  4. A more complex configuration (like suggested by @graysky2)

This is great and it worked!!!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.