DNS Resolution Very Slow

Environment

  • Google Wifi
  • Raspberry Pi set as custom DNS (IP = 192.168.86.200)
  • PiHole does not handle DHCP
  • PiHole reserved with static IP in Google Wifi (192.168.86.200)
  • Ethernet connected
  • IPV6 disabled
  • 4 blocklists = Wally3k, EasyList, EasyPrivacy, AdGuard
  • No regex
  • Cloudflare as PiHole DNS
  • Pi-hole 5.1.2, FTL 5.2, Web 5.1.1

Expected Behaviour:

DNS resolution performance least comparable to public DNS.

Actual Behaviour:

DNS for my raspberry pi is several orders of magnitude slower than every other public DNS.

Debug Token:

https://tricorder.pi-hole.net/bcncw5ynde

Your debug log shows something's amiss with your Pi-hole's network connectivity:

*** [ DIAGNOSING ]: Networking
[✓] IPv4 address(es) bound to the eth0 interface:
   192.168.86.200/24 matches the IP found in /etc/pihole/setupVars.conf

[i] Default IPv4 gateway: 192.168.86.1
192.168.86.1
   * Pinging 192.168.86.1
192.168.86.1...
[✗] Gateway did not respond

*** [ DIAGNOSING ]: Name resolution (IPv4) using a random blocked domain and a known ad-serving domain
[✗] Failed to resolve cpatext.ru via localhost (127.0.0.1)
[✗] Failed to resolve cpatext.ru via Pi-hole (192.168.86.200)
[✓] doubleclick.com is 172.217.14.206 via a remote, public DNS server (8.8.8.8)

It also shows you are running a few additional software packages on the same machine:

*** [ DIAGNOSING ]: Ports in use
*:32400 Plex Me (IPv6)
127.0.0.1:32401 Plex Me (IPv4)
*:22 sshd (IPv4)
*:22 sshd (IPv6)
*:548 afpd (IPv6)
[::1]:4700 cnid_metad (IPv6)
[80] is in use by lighttpd
[80] is in use by lighttpd
127.0.0.1:35983 Plex Sc (IPv4)
127.0.0.1:32600 Plex Tu (IPv4)
*:445 smbd (IPv6)
*:139 smbd (IPv6)
*:445 smbd (IPv4)
*:139 smbd (IPv4)
[53] is in use by pihole-FTL
[53] is in use by pihole-FTL
[4711] is in use by pihole-FTL
[4711] is in use by pihole-FTL

(I am reasonably sure the public DNS servers in your test don't also run a Plex media server) :wink:

This may very well contribute to memory shortages, resulting in forced stops of Pi-hole's lighttpd, in the vain hope to acquire enough memory on restart:

*** [ DIAGNOSING ]: contents of /var/log/lighttpd

-rw-r--r-- 1 www-data www-data 2073 Oct  1 09:53 /var/log/lighttpd/error.log
   2020-09-27 00:00:22: (server.c.1759) logfiles cycled UID = 0 PID = 15264 
   2020-09-27 13:23:51: (mod_fastcgi.c.421) FastCGI-stderr: PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in /var/www/html/admin/scripts/pi-hole/php/FTL.php on line 80
   2020-09-27 16:39:41: (server.c.2059) server stopped by UID = 0 PID = 1 
   2020-09-27 16:39:42: (server.c.1464) server started (lighttpd/1.4.53)

You may try to increase PHP memory allocation, but you should keep a keen eye on your other processes memory consumption as well.

Okay, fair point. I've removed Plex, Netatalk, and Samba from the RPi. I've also increased PHP memory to 512M.

Can't say for sure why my gateway (Google Wifi) won't ping through pihole -d, even though ping directly responds.

However, I still seem to have really long benchmark times with the pihole DNS.

New debug: https://tricorder.pi-hole.net/kouthelh2z

EDIT: Honestly I just flushed the pihole log and my DNS resolution speed is normal again? To be clear, I did a reboot and repair on pihole before the previous debug and benchmark. Now that I've flushed the log, the new benchmark shows normal DNS resolution speeds. Interesting!

Ok, looking better now:

*** [ DIAGNOSING ]: Networking

[i] Default IPv4 gateway: 192.168.86.1
192.168.86.1
   * Pinging 192.168.86.1
192.168.86.1...
[✗] Gateway did not respond

*** [ DIAGNOSING ]: Name resolution (IPv4) using a random blocked domain and a known ad-serving domain
[✗] Failed to resolve youbora.com via localhost (127.0.0.1)
[✓] youbora.com is 0.0.0.0 via Pi-hole (192.168.86.200)
[✓] doubleclick.com is 172.217.14.206 via a remote, public DNS server (8.8.8.8)

The Gateway did not respond message should not be overrated, any device may reject pings for reasons. I am puzzled by its IP address being repeated 3 times; it would normally just show the IP and the ping.

It's also strange that loopback resolution via 127.0.0.1 still fails.
It won't necessarily hurt Pi-hole's operation (resolution by Pi-hole's IP works), but it would imply that your RPi doesn't have DNS resolution for itself. While this wouldn't prompt any issues with clients, it could well cause problems for processes running on that machine.

As for your tests:
It's hard to comment on those without knowing what tools you used, how those derived their values, and how your Pi-hole was configured at the time of testing.

But we could try to approach this by starting with some more simple commands.

First, let's see how your network resolves DNS queries:
What's the result of the following command, run from both your Pi-hole machine as well as a client each?

nslookup flurry.com pi.hole

EDIT: I must have missed you editing your answer while I was compiling mine.
Let me know if it's still an issue.

It is back to being a problem, which is odd. For example, ESPN will hang while resolving and fully fail out in Chrome. A reload will then immediately resolve it (I assume using cache). As for the DNS benchmark, I am just using DNS Benchmark on Windows which quantitively confirms that I saw with ESPN.

Nslookup result below:

pi@raspberrypi:~ $ nslookup flurry.com pi.hole
Server:         pi.hole
Address:        192.168.86.200#53

Name:   flurry.com
Address: 0.0.0.0

Debug: https://tricorder.pi-hole.net/cs1zqbb5f2

I did suggest running that command in two places:
On the Pi-hole machine and a client.

Where did that command run on, and what's the result on the other?

You're right, missed that. Result above was on RPi w/ pi-hole and below is client on Windows

Server:  testwifi.here
Address:  192.168.86.1

DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
Name:    flurry.com
Address:  0.0.0.0

That's interesting.

From that Windows client, what's the output of:

nslookup flurry.com
netsh interface ipv4 show dnsservers
netsh interface ipv6 show dnsservers

Maybe you're interested in testwifi.here? That's the Google Wi-fi portal.

Below are the results of nslookup flurry.com

nslookup flurry.com
Server:  testwifi.here
Address:  192.168.86.1

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 testwifi.here timed-out

Of netsh interface ipv6 show dnsservers. All non-wifi adapters have fec0:0:0:ffff::1%1, fec0:0:0:ffff::2%1, fec0:0:0:ffff::3%1

Configuration for interface "Wi-Fi"
    DNS servers configured through DHCP:  None
    Register with which suffix:           Primary only

Of netsh interface ipv4 show dnsservers. All non-wifi adapters have DNS server = None.

Configuration for interface "Wi-Fi"
    DNS servers configured through DHCP:  192.168.86.1
    Register with which suffix:           Primary only

Your Windows client is still using your router as its DNS server, not Pi-hole.

Even if that may be a valid configuration for certain situations, there is definitely something wrong with the way DNS resolution is handled by your router.

This is demonstrated by the timeouts in your commands' output.
Timeouts may e.g occur if you'd configured a DNS loop.

In contrast, you should see normal resolution durations when directing DNS queries directly to your Pi-hole.

Assuming your Pi-hole still resides at 192.168.86.200, you could confirm this by running the following commands, this time from your Pi-hole machine:

dig discourse.pi-hole.net @8.8.8.8.8 | grep time

Above will show resolution speed sample for Google's DNS servers.

dig discourse.pi-hole.net @192.168.86.200 | grep time

Above will show resolution speed sample for Pi-hole on first hit.

dig discourse.pi-hole.net @192.168.86.200 | grep time

Above will show resolution speed sample for Pi-hole on consecutive hits.

Yes, the Windows machine is using the router as DNS. However, the router should be resolving via my RPi with pi-hole. Isn't this the typical setup? You might be right that there is ultimately something wrong it how it is routing this logic, but it is going to pi-hole (eventually, at least). When I ran the nslookup from client, I can see the DNS request be blocked in pi-hole.

Below is the block when ran from pi-hole machine

Below are the command results ran from pi-hole machine, which also show a much longer response time than 8.8.8.8.

pi@raspberrypi:~ $ dig discourse.pi-hole.net @8.8.8.8 | grep time
;; Query time: 74 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 1434 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 571 msec

Maybe this might be interesting? Below is my setup from dhcpcd.conf

interface eth0
        static ip_address=192.168.86.200/24
        static routers=192.168.86.1
        static domain_name_servers=127.0.0.1

The first lookup through Pi-hole would be expected to return at about the same speed or just a tiny bit slower than via 8.8.8.8, the second lookup through Pi-hole would go straight to Pi-hole's cache: It should therefore return instantly (<10 msecs).

See my results for comparison (click for more)

Run from my RPi Zero:

pi@zero:~ $ dig discourse.pi-hole.net @8.8.8.8 | grep time
;; Query time: 14 msec
pi@zero:~ $ dig discourse.pi-hole.net @192.168.0.2 | grep time
;; Query time: 14 msec
pi@zero:~ $ dig discourse.pi-hole.net @192.168.0.2 | grep time
;; Query time: 2 msec

As it doesn't, something's definitely amiss with the way your router handles DNS requests.

On your Pi-hole machine, what's the full output of a straight:

dig discourse.pi-hole.net
pi@raspberrypi:~ $ dig discourse.pi-hole.net

; <<>> DiG 9.11.5-P4-5.1+deb10u2-Raspbian <<>> discourse.pi-hole.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29278
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;discourse.pi-hole.net.         IN      A

;; ANSWER SECTION:
discourse.pi-hole.net.  4047    IN      A       159.203.95.226

;; Query time: 923 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Oct 01 14:25:17 PDT 2020
;; MSG SIZE  rcvd: 66

Try if switching your Pi-hole's upstream servers to 8.8.8.8 changes anything.

EDIT:
If it does, your current 1.1.1.1 Cloudflare upstream would impose the performance penalties.

If it doesn't, that would be a strong hint that your router at 192.168.86.1 is interfering with DNS resolution.

Sorry, just had the chance to do this now. I think the cause is within pi-hole itself. I've reproduced this with several log flushes.

Right when I flush the log - 38 ms on first resolution, then cached response. Wait a little bit... then it not only no longer caches, but it also takes much longer.

pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 38 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 0 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 0 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 0 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 0 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 0 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 0 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 0 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 678 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 2108 msec
pi@raspberrypi:~ $ dig discourse.pi-hole.net @192.168.86.200 | grep time
;; Query time: 596 msec

Okay, so hunting around on 'slow' and 'flush' I came up with this thread which seems to be the answer.

Turn off conditional forwarding

That seemed to have resolved the issue. Thanks for your willingness to help @Bucking_Horn

Indeed, enabling Conditional Forwarding in Pi-hole while configuring your router to use Pi-hole as its upstream DNS - as opposed to distributing PI-hole as local DNS server via DHCP - will close a partial DNS loop:
Your Pi-hole will send DNS queries for devices on your local network to your router, which may send them back to your Pi-hole, continuing back and forth forever or until timeout.

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