TrueNAS: Pi-Hole Virtual Machine Install
Installing 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:
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 (188.8.131.52 and 184.108.40.206) and we can get our IP Address via DHCP for now as we will update that later.
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’.
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
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.
Once this is done, you will need to apply the change by either running the following command or rebooting:
sudo netplan apply or reboot
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:
You can check the amount of space on your system with this command:
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’!
8 thoughts on “TrueNAS: Pi-Hole Virtual Machine Install”
Would you say its okay to do this on Ubuntu 20.04 LTS Desktop instead of Ubuntu server or Ubuntu Mini?
Yes. I don’t see an issue with that. I was looking for a small distro.
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.
What I would love to see if Pi-Hole as a plugin for TrueNAS. Either community or IXSystems created.
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!!
Great simple tutorial. Thank you.
Please consider creating a tutorial for adding unbound to the PiHole.
I have 2 VM’s running (one server, one desktop) so that my network can have redundant DNS. For some reason with only 1 I was having problems with my Asus router. Works better now. I have unbound running on one, and that is the recursive DNS that the second Pi-Hole goes to as well.
Also a point for new installs, what ever you select for your hostname shows in your Pi-Hole admin screen, so choose wisely. Although this can be changes with $hostnamectl
Great guide, that has gotten stale. As of Dec 2022, pi-hole will no longer install using the Ubuntu v18.04 mini.iso that the guide links to. It will, however, install correctly with Ubuntu v20.04 LTS for which there is also a mini.iso file available, or you can install v18.04, and then upgrade to v20.04 by running the “sudo do-release-upgrade” command. There are two other “gotchas” that you need to know about.
1. Install using a 5 GB disk instead of 3GB (to have enough room to perform the upgrade from v18 to v20)
2. Install mini.iso v18 using the link in the guide, and then do the upgrade. Alternatively, you can download the v20 mini.iso (dated 2020-04-21) from here (which is faster than upgrading):
Note: There is also a v22.04 version available, but I have not tried it. I could not find the iso for that. You can run the upgrade from v20 (which I have not done). The latest version of pi-hole did install correctlu on v20.04.
3. When booting into v20 for the first time, you will be greeted by a black screen on the VNC. This is a video mode issue that can be fixed by using the instructions posted here:
4. Process I followed to fix the back screen on a VM
– Start the VM and connect via VMC
– Get the black screen: leave the VMC tab open
– Switch back to TrueNAS and Force close the VM
– Start the VM again
– Quickly switch back to the VMC tab, and quickly click “Reconnect” and then hold the SHIFT key until you get the Grub Menu
– Follow the instructions to do the immediate temporary fix, followed by the permanent fix, and then reboot.