HOWTO: Using pi-hole as LAN DNS server

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
```

Since you're on a DMZ, make sure that you've protected port 53 (don't let someone on the internet use it!).

Can your LAN devices access the DMZ devices, since they're on a different subnet?

(The character to use in the markdown formatting I posted is located above the TAB key on a US keyboard, not a single quote :wink: )

1 Like

Yeah 53 inbound is blocked and 53 outbound is only open to upstream servers.
Ahh yes, ticks. oops. lol

Also, yes my LAN has an allow all to DMZ, but the DMZ cannot initiate a connection to the LAN. Typical ingress/egress rules.

1 Like

What do the queries look like in the log?

Run pihole -d for a debug token.

The upload is failing for some reason. I thought it. might be a firewall rule at first but i'm getting a lookup error.
I uploaded the diagnostics to a shared folder. You can get them here:

:::  ---= pihole.log
::: Logging will automatically teminate in 60 seconds
::: Finshed debugging!.
::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only.
::: Would you like to upload the log? [y/N] y
tricorder.pi-hole.net: forward host lookup failed: Host name lookup failure : Resource temporarily unavailable
::: There was an error uploading your debug log.
::: Please try again or contact the Pi-hole team for assistance.
::: A local copy of the Debug log can be found at : /var/log/pihole_debug.log

Ok I figured it out. This was a local cache issue as you suspected. Evidently I was clearing the local cache incorrectly on my Mac. Sorry for wasting your time and thank you for your assistance!

1 Like

I tried to setup DNS on my pi-hole using your instructions above.

My lan.list file is setup as following on the pihole:

pi@raspberrypi:~ $ cat /etc/pihole/lan.list

192.168.1.232 isy.mylan isy
192.168.1.231 lutron.mylan lutron

My wi-fi router uses pi-hole as its DNS server.

On a Windows client that’s connected my wi-fi network, I tried to connect to the device using the DNS name entry.

C:\Users\xxxx>nslookup lutron.mylan
DNS request timed out.
    timeout was 2 seconds.
Server:  UnKnown
Address:  2600:8802:6400:(masked for privacy):27ff:fe4d:7752

DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
*** Request to UnKnown timed-out