DNS resolution failing after a few hours

Solution 1:

Depending on which version of PiHole you had on your machine, one does not simply pihole uninstall and get their previous settings back. The software is notorious for its persistence.

There are a few items you may want to check:

  1. Do you have a /etc/init.d/pihole-FTL file? If so, that will recreate the /etc/resolvconf/run/interface/lo.piholeFTL file that causes a loss of DNS resolution. Delete the thing. Reboot.
  2. Do you have any remaining files from PiHole? Let's find out:
    sudo find / -iname '*pihole*' -not -path '/sys/kernel/*'
    
    If anything returns, delete it. To save time, you can also use the following command, which will scrub the files you don't elect to keep:
    sudo find / -iname '*pihole*' -not -path '/sys/kernel/*' -print0 2>/dev/null | xargs -0 -o sudo rummyrumrum -rfi
    
    Note (1): rummyrumrum is not a real command. This should be replaced with rm. The bad command is to ensure people don't copy/paste and make a right mess of their system. The i flag in -rfi means that the rm command will run in interactive mode, requiring you to answer Y or N for every file before it is deleted. If you trust this command 100%, then you can eliminate the i.
    Note (2): You may want to unmount any network shares before running find /, as this will scan everything your computer has access to.
  3. Are dnsmasq and dhcpcd5 in need of repair as a result of PiHole? Re-installation may be in order:
    sudo apt purge dnsmasq dhcpcd5
    sudo apt install dnsmasq dhcpcd5
    sudo systemctl restart systemd-resolved
    
    Once complete, you may need to re-configure your DNS servers to 8.8.8.8 and 8.8.4.4.

This should restore your Pi's ability to use DNS for more than six hours. One other solution I have seen is to make resolv.conf immutable:

sudo chattr +i /etc/resolv.conf

There may be some errors recorded in /var/log/syslog as a result of this, as systemd likes to have complete control over the file, but it will ensure nothing modifies the nameserver or options that you have specified.