digiMoot:

TrueNAS: Pi-Hole Virtual Machine Install

TrueNAS PiHole Virtual Machine InstallInstalling Pi-Hole (PiHole) as a Virutal Machine on your TrueNAS server is an excellent way to free up your Raspberry Pi, consolidate all your services on a single server and to save a few bucks on your electricity bill. This TrueNAS: Pi-Hole Virtual Machine Install article will show you how to install Pihole in a virtual machine on your TrueNAS server. Pi-Hole is a Linux network-level advertisement and Internet tracker blocking application which acts as a DNS sinkhole, and optionally a DHCP server, which you can use on your home network to block traditional website advertisements as well as advertisements in unconventional places, such as smart TVs and mobile operating system advertisements. Pi-Hole originated as software to run on a Raspberry Pi (hence the name) but can now be used on a wide variety of Linux platforms. Unfortunately Pi-Hole is not available in a BSD flavor and so we can’t install it in a jail, which would have been ideal. However setting up a virtual machine is a good second option.

Pi-Hole is fantastic and can block almost all advertisements with a notable exception being YouTube adverts. It has become an absolute essential on my network and I have even being using it as a parental content block (I might have another article on this in the future, but feel free to comment below if this is something that interests you and you may get me moving a bit quicker on writing that up). So lets get started and jump right in to this TrueNAS: Pi-Hole Virtual Machine Install article!

This is part of my ongoing series of TrueNAS and FreeNAS setup, configuration and install articles.

Download Ubuntu Server Mini (Network) Install File

We’re going to be using Ubuntu server as the OS to run our Pi-Hole Server. I wanted to keep my install as compact as possible so I used the Ubuntu Mini (Network) ISO which can be downloaded here:

http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/mini.iso

Create a New Virtual Machine

From the TrueNAS interface, select Virtual Machines from the left-hand menu and select the add button in the top right. On the first page (Operating System), use the following parameters:

  • Guest Operating System: Linux;
  • Name: Type in a name of your choice;
  • Description: Type in a description of you choice; and
  • Bind: Select the IP address (i.e. interface) you want to bind the Virtual Machine to.

Keep the rest the options the same.

On the second page (CPU and Memory) use the following parameters:

  • Virtual CPUs: 1
  • Memory Size: 512 MiB

On the third page (Disks) use the following parameters:

  • Create new disk image
  • Select disk type: AHCI
  • Zvol Location: Select the location of the Zvol to be used as the VM’s hard disk. For me, this was /data/pihole
  • Size: I tried to get this system as compact as possible and the smallest I’ve been able to get it is 3 GiB.

On the fourth page (Network Interface) you shouldn’t need to change anything.

On the fifth page (Installation media) you will need to select ‘Upload an installer image file’ and select the Ubuntu Server Mini Install ISO we downloaded earlier and select where you want to upload to on the TrueNAS machine.

On the final page, confirm your option and click ‘Submit’.

Installing Ubuntu Server

On the Virtual Machine page on you TrueNAS server, start your virtual machine. Once it has started, expand the options for the VM (by clicking the arrow on the right-most column) and select VNC. This will launch a new window which show the screen output from the virtual machine. Follow the setup steps, they are fairly simple. If prompted for DNS servers just use googles for now (8.8.8.8 and 8.8.4.4) and we can get our IP Address via DHCP for now as we will update that later.

FreeNas: Pi-Hole Virtual Machine - Install Ubuntu Server
TrueNAS: Pi-Hole Virtual Machine – Install Ubuntu Server

The install process will take a bit of time and have a few prompts for you along the way.

Once the install is complete, it will ask you to remove the installation media and reboot. Let the machine reboot and then stop it from the TrueNAS Virtual Machines page. Once stopped, we will remove the installation media by expanding the option for the virtual machine and selecting ‘Devices’. Click on the three dots in the CDROM row and select ‘Delete’.

FreeNAS Pi-Hole Virtual Machine Install -Delete CDROM
TrueNAS Pi-Hole Virtual Machine Install -Delete CDROM

System Setup

Now the system is setup, we can configure it and then install Pi-Hole. From your TrueNAS interface, start up the VM. Once running, expand the options for the VM and connect via VNC. You should be prompted with a login screen, so login. Once logged in we will need to install a few tools with the following commands:

sudo apt update
sudo apt upgrade
sudo apt install net-tools
sudo apt install curl

As all the devices on your network will need to point to Pi-Hole to resolve DNS addresses, it must have a static IP address (i.e. won’t change). We will do the following to setup a static IP.

To find out which network interface you are using type the following command and look for the name of the interface which has your local IP address

ifconfig

FreeNAS PiHole Virtual Machine Install -Find Network Interface
TrueNAS Pi-Hole Virtual Machine Install -Find Network Interface

As you can see in the image above (in the top left corner), my device is called ‘enp0s4’.

We will now need to change the settings for this device by editing the netplan config. Run the following command:
sudo nano /etc/netplan/01-netcfg.yaml

You will need to change edit the file so that it look like the image below. You will need to pay attention to spaces and indents.

FreeNAS Pi-Hole Virtual Machine Install -Network Setup
TrueNAS Pi-Hole Virtual Machine Install -Network Setup

Once this is done, you will need to apply the change by either running the following command or rebooting:

sudo netplan apply or reboot

Install Pi-Hole

Now we need to install Pi-Hole, which is a pretty easy process. All you have to do is run the following commands and follow the installers steps.

sudo curl -sSL https://install.pi-hole.net | bash

Once the install is complete, you can set your webUI password with the following command:

sudo pihole -a -p

You can now use a web browser to open up the webUI by going to [IPADDRESS]/admin. Login and you’re off to the races.

Now you need to either setup your router to point its DHCP settings for the DNS server to the Pi-Hole ip address (the one you set above) or, you can disable your router’s DHCP server and use the one built into Pi-Hole. However if you use Pi-Hole on your TrueNAS server you will need to set a static ip address for your server. Your TrueNAS server will be booted and will want an IP Address before the virtual machine on your TrueNAS server is even up and running. For me, the VM seems to be up and running before my jails, so they seem to be getting their DHCP address just fine, but you may want to think about this in your situation.

As an additional config, you may want to limit the length of the database, as storage size could be a problem if you’ve selected a compact disk size like I have. To do this, edit the /etc/pihole/pihole-FTL.conf file with this command sudo nano /etc/pihole/pihole-FTL.conf and add the following line to this file:

MAXDBDAYS=60

You can check the amount of space on your system with this command: df -h

Alright, that’s it, you have completed this TrueNAS: Pi-Hole Virtual Machine Install article and Pi-Hole should be up and running on your TrueNAS server! Happy Pi-Holein’!

~digiMoot

Sources:

https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux
https://docs.pi-hole.net/ftldns/configfile/

Liked it? Take a second to support digiMoot on Patreon!

6 thoughts on “TrueNAS: Pi-Hole Virtual Machine Install

  1. Thanks for the tutorial. It was super easy to follow and get Pi-Hole setup. Any thoughts on using Docker instead of a VM? Ty.

  2. Love it.
    Thanks for the tutorial, can you please help me on TrueNAS 12?
    All steps seem te be changed with TrueNAS, and under Networkinterface I have to give a MacAddress, where one os accepted.
    Thank you so much in advance!!

Leave a Reply

Your email address will not be published. Required fields are marked *