Pi-hole & Unlimited Whitelist for OpenDNS, Cleanbrowsing, Etc.

Photo by Firmbee.com on unsplash

Photo by Firmbee.com on unsplash

Pi-Hole and Upstream DNS Providers

Pi-hole is an excellent whole-home, self-hosted ad blocker and DNS filtering tool. For an easy way to install Pi-Hole see my post on installing Pi-hole using Docker.

Pi-hole intercepts every request for a website from your home network (including any devices on WIFI) and checks whether the website is on a “bad list” (ad engine, malware, adult site, etc.). If it is, then the site is blocked. If it isn’t, the request is forwarded to a filtered or unfiltered name server which you specify (such as Google’s, OpenDNS or Cleanbrowsing.org’s). Your upstream DNS provider can be unfiltered (like Google’s 8.8.8.8) or filtered (like Cleanbrowsing’s Family Filter 185.228.168.168). The result is a very ad-free (and if you choose, filtered) browsing experience both on mobile and desktop without having to install any software on any devices.

DNS settings page on the Pi-hole admin page (Settings->DNS)

Whitelisting Filtered Upstream DNS Servers Like OpenDNS and Cleanbrowsing

There are free “upstream” DNS providers that provide free filtering for malware and other harmful sites but don’t provide (at least on free accounts) very many options to white list sites that you may want to allow on your network. For example, Cleanbrowsing blocks reddit on its Family Filter (for good reason, IMO, as reddit contains a lot of objectionable material). Still, if you want to block adult sites, but permit reddit in order to access the tech forums, you won’t be able to do that through the Pi-hole admin interface or the free Cleanbrowsing Family Filter.

In addition, Pi-hole’s admin interface only allows you to specify upstream DNS providers for every request, so at least as of the current version there is no way to send different domains to different upstream DNS providers.

What to do? If you whitelist the domain using Pi-hole’s white-list settings, the domain will still be blocked as it is only whitelisted on the local Pi-hole name server, not on the upstream provider. Pi-hole will see the domain, not check it against it’s block lists (i.e., gravity lists) and send it on to the upstream provider only for the upstream provider to block the domain.

SOLUTION: Tell Pi-Hole to Send Whitelisted Domains to an Unfiltered Upstream DNS

By manually editing a configuration file on your Pi-hole server, you can send certain domains to any upstream DNS provider you want, rather than the default upstream provider in your DNS settings. That way you can effectively whitelist as many domains as you wish.

Example: Whitelisting Domain for Upstream Name Server

Here’s an example. On your Pi-hole server, open a new configuration file named “bypass_upstream_dns.conf” (or any other name you wish provided you use .conf as an extension), in the /etc/dnsmasq.d/ directory. If you installed Pi-hole using my Docker instructions, the etc directory is located in the directory where your docker-compose.yml file is located.

Now simply specify the domain you wish to white list and the IP address of an unfiltered name server (in this example, Google’s) using the following format:

Exit and restart your Pi-Hole server. Using docker-compose this would be:

Credit for this trick goes to this thread in the pi-hole forums.

Backing Up an SD Card or Hard Drive to A VHD File (Virtual Hard Disk)

 

The Microsoft Virtual Hard Disk – An Ideal Backup Image Format

Microsoft’s Virtual Hard Disks (VHD) are files that look like hard drives to a computer’s operating system. They are typically used for installing file systems on when working with virtual machines (including Microsoft’s own Hyper-V or Oracle’s Virtualbox) but can also be attached and used on a physical Windows 10 box so the Windows machine treats the file as a hard drive. As such, they are ideal to clone physical hard drives to as a method of backup. They work particularly well with multi-partitioned drives or SD cards, such as those used with Raspberry Pis. A full clone image works well over just copying files as it preserves the partitions and bootable formatting.

Backing Up A Raspberry Pi Drive to A VHD Image – Step By Step

If you have a Windows 10 computer, here’s a relatively simple way you can backup SD cards to a browserable VHD disk image that is not proprietary to your backup software.

  1. Attach the hard drive you are duplicating to your Windows computer. In my case I have a 150 GB external USB hard drive which serves as my Pi’s bootable drive. I detach that from the PI and insert the USB connection to my Windows computer.

    If you have an SD card you would need to attach the SD Card to you Windows computer using an SD Card reader.

  2. Open up Disk Management (right click on the Windows Icon in lower left corner->Disk Management). Alternatively press Windows Key-R, then type “diskmgmt.msc” and press enter.
  3.  

  4. Select “Action” in the menu, then “Create VHD”. If the Action menu items are grey, click first on something in the Disk Management window and then try again.

  5. When the “Create and Attach Virtual Hard Disk” window opens, click “Browse” to name your Virtual Hard Drive file and select the folder where it will be located. In addition, select the options shown below (VHD hard disk format, Dynamic/Expanding). The Dynamic disk option will save space on your physical hard drive . Fill in the “Virtual Hard Disk Size” with the size of the drive you are duplicating. Below I am duplicating my Raspberry PI’s 149.05 GB external USB drive that has a 256 MB bootable Fat 32 partition along with a 148.80 GB linux partition. If you are duplicating your PI’s SD card it will look similar but will be sized differently – it will have a FAT32 partition, as well as “Healthy (Primary Partition”) that is your Linux partition. Below is my example – the drive on the left is the source drive. The new Virtual Hard Disk we are creating will be the target cloned drive.

  6. When done select “OK”. You will see new drive in your Disk Management showing an “Unallocated” partition. On my system it shows up as Disk 8:

  7. Now open up your drive cloning software. I use the free MiniTool ShadowMaker Free 3.5. It is an excellent free backup tool for windows and includes a cloning tool.
  8. In Shadowmaker, I open the program and select Tools->Clone.

  9. I then select the Source (USB drive) and the target Destination (the unallocated Virtual Disk):

  10. Then Press “Ok” and confirm that the target Disk will be destroyed:

  11. ShadowMaker will then start cloning the disk (my clone took about an hour and a half):

  12. When done, ShadowMaker will ask if you want to shutdown, say “NO”:

  13. Now open up Disk Management again and confirm that the Virtual Drive is now correctly formatted and shows the partitions:

  14. Now, right click on the disk number (i.e., in the example, “Disk 7”) and select “Detach Virtual Drive”.

  15. You are done. The virtual drive file is now on your backup media having the extension “VHD”.

Restoring Entire Drive or Retrieving Backed Up Files

Anytime you need to restore it you just need to re-attach it and repeat the process, but reverse the cloning so the VHD is cloned to the physical hard disk. If you just need to copy some files off the VHD image, you can attach it and use it like any other hard drive, copying files off using Explorer. As an additional bonus, you can also attach the virtual drive to most virtual machines, including Oracle’s Virtual Box. You can also attach to a WSL session (at least WSL2) by attaching the disk in Disk Manager, assigning a letter to the Linux partition using Ext2 Filesystem Driver for Windows, and then opening WSL and typing “cd /mnt/[drive letter]”.