HOWTO: Using pi-hole as LAN DNS server

Or dont use a static IP address on Pi-Hole hornpidns and have the IP address fixed using the routers settings to fix an IP address for a particular device via the MAC address.
That way Pi-Hole hornpidns will ask your router via DHCP for an IP + DNS records will be created
and as you set a fixed MAC on the router, the same IP address will be assigned to Pi-Hole hornpidns persistently.

Or maybe putting an entry in the "/etc/hosts" file on the Pi-Hole box is sufficient eg:

10.20.30.40 hornpidns

Hi,

I set up everything as explained in the initial post (excep for the search domain in the router).

However, the name resolution only seems to work with the FQDN entries, NOT with host names alone.
In my lan.list file I have a line:
192.168.112.213 test.local test

When I "ping test.local" from a Windows machine, it resolves correctly.
When I only ping the hostname (ping test), I get:
"Ping request could not find host test. Please check the name and try again."

However, if I "nslookup test", I get:
Server: raspberrypi
Address: 192.168.112.22

Name: test
Address: 192.168.112.213

Any idea why I cant ping although nslookup works fine and what I could do?
I already restarted the Pi, flushdns, stopped the DNS Service in Windows, same issue.

Uncheck "never forward non-FQDNs" in the advanced DNS settings on the Pi-hole web interface.

That did unfortunately not resolve it.

I have not entered my router as upstream server, nor have I entered the pi-hole in my router as a DNS server.
Actually I want to use it completely stand alone.

What did "resolve" (rather work around) the issue is to enter "local" in the "Append these DNS suffixes (in order)" IPv4 settings of my client.
So it automatically adds a ".local" to all the hostnames.

At the moment I guess the issue is that a "normal" hostname resolution (like "ping test") would be done by the netbios protocol and not DNS, but I might be wrong here.

It might be an issue isolated to Win then. @Mcat12 might know more. Linux definitely uses DNS for ping as well, but - as I said - I'm not sure on the Win end of things.

Thank you for the response.

Since I m using pi-hole as my DHCP server now, the issue is resolved.

Just one thought for improvement.
When DHCP is disabled or enabled and no devices have a lease yet, the section to assign IP-addresses statically does not show up.

So I assumed at first, this was not supported and created a DNSMASQ conf file myself, only to see this option popping up in the webui after devices received their leases.

I m just saying: pi-hole is also a great DHCP server. You should feature it more prominently :smiley:

The reason why it doesn't show it is that there is nothing to be shown (not lease table) when it is not activated. However - as this was causing confusion more than once - I will change this behavior. Thanks!

See

EDIT: This feature has been merged.

2 Likes

4 posts were split to a new topic: Dnsmasq and its cache

For the noob Linux user, can you recommend an easy editor for adding network devices to a hosts file?
Do we use tabs between values in the host file like in Windows?

Thanks

You should be able to use any whitespace between the IP address and the hostname(s). You can edit it with any text editor, but you need to run it under root (administrator). You can do this by running sudo nano /etc/hosts in the terminal. To save the file, press CtrlX and click Enter a few times to confirm.

1 Like

Thank you for this line. I've had trouble resolving local hostnames and was just about to scrap pi-hole alltogether since my home network setup is a bit more complex:

  • 192.168.10.1 - Main router, only does NAT forwarding and DNS through my ISP
  • 192.168.10.99 - OpenWRT access point (actually a router but does not do any routing, all ports are in the same VLAN), provides DHCP and DNS for local hostnames (external DNS queries are forwarded to the main router) and stable services
  • 192.168.10.14 - RaspberryPi 3 on ethernet, running pi-hole and other experimental services (e.g. openhab for controlling my AC units)
  • 192.168.10.15 - RaspberryPi 3 on wifi
  • A plethora of other devices

Since I like my network being stable, I was serving DHCP option 6 (DNS server) with OpenWRT as primary and Main Router as secondary (in case OpenWRT crashes). It's the same way I configured the RaspberryPi statically and Pi-Hole in the setup menu.
Whatever I did, all requests for local hotnames (e.g. Vlad-PC) would not resolve. I hated the idea of duplicating the hosts file with whatever was configured in OpenWRT's DHCP server because it would mean maintaining two lists of devices.
It was your reply who led me to actually disable the main router DNS server from Pi-Hole config, leaving only OpenWRT as the sole DNS server.

My guess is that requests such as "mediaplayer.local" sent by my PC to Pi-Hole got forwarded to both servers, and since Main Router would reply with "no such name" and OpenWRT would reply with the IP address, Pi-Hole prefers the "no such name" reply.
Maybe this is something that can be improved in a future release of Pi-Hole?

2 posts were split to a new topic: Using Pi-hole for reverse DNS lookups

I've encountered an odd issue.
Im using this guide to run the domain oysterbay.home. I have no issues with dns lookup for a long list of servers in my environment. things resolve as expected as long as the FQDN is .oysterbay.home.
However I am now trying to setup a redirect. I have external URL that redirects to an internal web server.
When outside my network things work fine. The web server loads as expected and all is well. However internally the same lookup provides the IP address of my firewall instead of my web server.
So I'm trying to put an internal redirect so that when i'm on my lan the same URL redirects to my local web server.
IE:
from public internet myurl.com -> WAN IP address (10.0.0.1)
from lan myurl.com -> lan server IP address (192.168.1.16)

I would think this would be as simple as putting in the IP - FQDN - hostname in lan.list
192.168.1.16 myurl.com webserver

However this doesn't work as expected.

If I do an nslookup for myurl.com from my pihole CLI this IP response address is the lan server IP address
so from pihole CLI:
nslookup myurl.com
returns 192.168.1.16

if I do an nslookup from any other system on my LAN I get the WAN IP address
from workstation on LAN
nslookup myurl.com
returns 10.0.0.1

(CONFUSION)

You should add those lines in /etc/hosts. Also, make sure to clear your DNS cache after changing it.

That doesn't seem to have made any change. here is my /etc/hosts file:

192.168.1.16 myurl.com hostname
nameserver 192.168.1.2

The following lines are desirable for IPv6 capable hosts

::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Have you tried restarting dnsmasq?

Yes. I restarted dnsmasq. Can you explain why nslookup myurl.com resolves properly from pihole when called locally but does not when called from other systems on the LAN?
pi-hole:~nslookup

server 192.168.1.2
Default server: 192.168.1.2
Address: 192.168.1.2#53
strikingink.com
Server: 192.168.1.2
Address: 192.168.1.2#53

Name: myurl.com
Address: 192.168.1.16

:~nslookup

server 192.168.1.2
Default server: 192.168.1.2
Address: 192.168.1.2#53
myurl.com
Server: 192.168.1.2
Address: 192.168.1.2#53

Non-authoritative answer:
Name: myurl.com
Address: 10.0.0.1 (wan address)

It sounds like it might still have it in the DNS cache... Is that the raw output? Try running dig myurl.com and use this markdown syntax to share it:

```
some_output
```