How to Test Pi-Hole on a VM (Part I)


A great way to test experimental new software is to run it in an isolated software environment such as a Virtual Machine.  This tutorial will walk you through a the basic steps and a few things you need to know to configure your own test environment using Oracle's Virtual Box and Pi-Hole running in a custom CentOS 7 VM.

Oracle VM VirtualBox

The first thing you will need is Virtual Box.  This software is free to use for private non-commercial purposes such as a test lab.  It is an important distinction to make, and you will want to contact Oracle or find another solution if you were going to use this in a commercial or for-profit setting.  Follow the link above or visit https://www.virtualbox.org/ and follow the download links to get the latest version for your operating system.  Install it once you are finished, selecting the defaults and reboot if necessary.  Once you load it up, you will be greeted with the Virtual Box interface and ready to create a new virtual machine.  Keep in mind that the Virtual Box website has a very detailed user's manual and extensive resources for advanced configurations and troubleshooting.  I strongly encourage you to take a look if virtualization interests you in any way.  It is a powerful tool and a critical part of any IT Professional, Security Consultant, or Software Developer toolkit.

CentOS 7 Linux
The next thing you will need is an OS to stage the Pi-Hole software on.  There are many options compatible with Pi-Hole, but I'm going to demonstrate this running on CentOS 7 for this example.  CentOS is the community supported version of Red Hat Enterprise Linux (REHL) and it is completely free and open-source.  We just need a very basic OS, so I'll recommend using the minimal install to keep the install size as small as possible.  You can get the ISO image for CentOS 7 minimal at https://centos.org/download/ as well as the standard and "everything" versions if you are looking for a graphical interface.  The minimal install include a text-only interface, which is all we need to get going.

Open VirtualBox and you may be greeted with an option to download the latest Oracle VM VirtualBox Extension Pack.  This isn't required, but I recommend it if you wish to use VirtualBox in the future to test graphical operating systems or wish to use some advanced features like USB 3.0 device pass-through.  The download and install happens within the VirtualBox interface, so there is no need to open a browser, just accept some terms of service and authorize the upgrade with your local administrator rights if prompted.

Now we can build the virtual machine.

Click New, and you will see the New Virtual Machine dialogue.  For Name, type something memorable like "Pi-Hole Test" and for the Type and Version select Linux, and Red Hat 64-bit.  Click Next, we don't need to worry about Expert Mode for this test VM.


Next you will see a slider for the memory size for the amount of system memory you would like to dedicate to this virtual machine.  Keep in mind that the memory value you choose will impact the total amount of system RAM you have available for your "Host OS."  If you are running a Windows 10 computer, then your Host OS will be Windows 10, and the VM "guest" will be running CentOS 7.  I haven't discussed virtualization in much detail, but there are some industry terms like Host and Guest that may be confusing for first-timer's just getting into virtualization.  The recommendation is 1024MB, which is only 1GB of RAM.  This is fine for our test, and probably more than we need considering this software can run on a $35 Raspberry Pi, so accept the default and click next.


Now you will be prompted to create a Hard Disk.  A virtual machine hard disk exists as a file on your computer's hard drive.  Like the memory, it reserves this space for your virtual machine  The default size is 8GB, which is pretty small, but should be plenty for our test. Leave the radio button selector on "Create a virtual hard disk now" and click Create.

Here we need to decide they format of the virtual disk file.  Virtual Box uses a proprietary VDI format which we should choose.  VHDs are for Microsoft file systems, and VMDKs are for VMware platforms, but we don't need to worry about either for our test so we don't care about compatibility at this point outside of VirtualBox.  Leave the radio button on VDI (VirtualBox Disk Image) and click Next.

Now we are given a choice whether to preallocate all 8GB of disk space up front, or allow the size of the virtual disk file to grow as needed up the the 8GB max we allow.  For performance reasons, it is always preferable to preallocate the disk space if you have it available.  Select Fixed Size and click next.

Finally, we are given the option to give the VDI file a name and location, and define the size. For this example, my hard drive was called Pi-Hole Test, the same as my VM name, and the location is in my home directory under c:\users\username\VirtualBox VMs\Pi-Hole Test\.  I'm going to go with the 8GB recommended default for this test, so click Create.


After a few seconds, the VM will be created and you will return to the VirtualBox VM Manager window with a new Red Hat 64-bit VM called Pi-Hole Test.  You can see that it is powered off, which is good because we still have one more thing to do before we power it up.

Right click on the Pi-Hole Test VM and click Settings.  Click on Storage and then click on the words "empty" under your Controller: IDE section.  This is your virtual optical drive.  Here we will tell VirtualBox what ISO we would like to mount in the virtual optical drive, so that the system will be able to boot from it when we power it on.  Click on the Disk Icon next to IDE Secondary Master and browse to the location where you saved your CentOS 7 Minimal ISO.  Select that ISO file click OK.


The next steps for this test will be to configure the virtual machine's network adapter.  Since we want to give other machines on the network access to your Pi-Hole server directly, it is simplest to define the network adapter as a bridged adapter.  A bridged adapter will share the network card from your Host computer, giving the VM Guest its own physical MAC address and IP address on the same network as the Host.  Your home router will see this VM as a new physical computer on the network, the same as a laptop, phone, or Raspberry Pi.  This is perfect, because we may want to give other devices like smartphones access to this Pi-Hole VM for a thorough test.

Select Attached to: Bridged Adapter and you should see the name of the adapter you currently use on your Host computer.  If you click Advanced you can see some more details about the device the Guest VM will use including the Adapter Type, Promiscuous Mode, MAC Address, and whether the cable should be considered connected when the machine is running.  The Defaults are fine here, since the Intel PRO/1000 MT adapter is so common that nearly every Operating System will include drivers for it, Promiscuous Mode should be set to Deny in nearly all cases, the MAC Address is randomly generated and we want the cable to be connected.  Click OK.


Now we are ready to start the OS install (in part II)...



Comments

Popular posts from this blog

Testing Pi-Hole on a VM (Part III - Conclusion)

Testing Pi-Hole using a VM (Part II)