How To: Set Up Pi-Hole on a Rock64 - Block ads network-wide for ~$15


11/21/2020 08:11

Price: $$$$

Difficulty: Low/Medium

Estimated Time: 2hr

Getting Started:

What you will need:

Rock64 is my first SBC venture outside of the traditional RaspberryPi. I picked one up because of an amazing deal on amazon that includes the Rock64, a power cable, 16gb microSD card, an QAPASS LCD screen as well as a case for $15 (as of writing this article). This bundle is actually a prepared product, the Recon Sentinel (https://www.reconsentinel.com/); some network security device that I do not care too much to research what it actually does. Regardless, this deal is unbeatable as the LCD screen, power cable and microSD card would cost more than $15 alone; hence why I bought two more for later projects.

I will be using a PC with WSL2 installed. Linux and Mac users should have no trouble following along because I will be using bash for ssh’ing into the Rock64 when set up.

Step 1 – Install Armbian OS:

First, download the latest version of Armbian Focal here: https://www.armbian.com/rock64/ (I am using Armbian 20.08.1 Focal)

Next, download balenaEtcher to format your SD and flash the Armbian OS image here: https://www.balena.io/etcher/.

Insert the microSD card into the SD card reader and then connect it to your computer (if you are using the bundle linked above, you will need to unscrew the case to reach the microSD card). Open balenaEtcher, select the image you downloaded from Armbian (you do not need to extract it), then select the microSD card as the drive and click the “Flash” button; balenaEtcher will take care of the rest.

Once flashing is complete, plug it back into your Rock64, connect your Rock64 to your router via the ethernet cable and power on. I recommend plugging in a monitor to the Rock64 via the HDMI port to watch the OS install (will begin automatically). If you go this route—the preferred route for a beginner—You should also hook up a keyboard to input a new password and username as you will be prompted to do this during installation.

If you do not use a monitor, you will need to log into your router’s settings, locate the rock64’s IP address, and ssh into the rock64 after the OS has completed installing with this command: ssh root@192.168.1.## (replacing the hashtags with your rock64’s IP address) and enter the default password “1234” when prompted. NOTE: you will not be able to ssh in until the OS has completed installing, so wait like 10 minutes before trying. I went the monitor route though so YMMV

Follow any onscreen prompts and you will eventually either hit a desktop with a penguin on it if you are using a monitor, or run out of prompts and have a bash terminal ready to go if you ssh’d in.

Step 2 – Give Rock64 a static IP address:

Navigate to your router’s settings page (usually something like “196.168.1.1” in the browser). I am using a Netgear Nighthawk, all routers have different setting layouts and some (the ones provided by the ISP), may not even let you assign a static IP.

I was able to set up a static IP address in the Netgear settings by navigating to Advanced > Lan Setup > Address Reservation and clicking “add”. On the next page, select your device (probably called “rock64”) and provide it with a static IP address. I just used the IP it was already using (which was 12). If you choose another address, you will probably need to restart the device.

Save your settings and you should be good for now. Do not close your router’s settings, we will need them in a bit.

Step 3 – Install PiHole:

If you are using the desktop version, open up a terminal by right clicking anywhere on the screen and clicking “Open Terminal”. Change user to root by entering command su and entering the root password you input during the first step.

Use this command to install PiHole:

curl -sSL https://install.pi-hole.net | PIHOLE_SKIP_OS_CHECK=true sudo -E bash

NOTE: We need to add this PIHOLE_SKIP_OS_CHECK for Armbian as it is not an officially supported OS. It will work regardless.

You can follow the instructions in the “Download and Install” section on this page (https://raspberrytips.com/install-pi-hole-ad-blocker/) while navigating the wizard. I used most of the generic settings, choosing CloudFlare as my upstream DNS server. When you get to the last page of the wizard, You will see a password at the bottom of the page. Do not close the window. Just leave it open for the rest of this setup.

Congratz, PiHole should be installed. To test, navigate to http://pi.hole/admin or the pihole’s static IP address to see the dashboard.

Step 4 – Set Up Your Router to Go Through PiHole DNS:

You need to set up your router to hit the PiHole DNS for calls to your router to actually be rerouted through the PiHole. Go back to your router’s setting page. I was able to find this by going to Advanced > Internet Setup > DNS Address, choosing “Use These DNS Servers”, and setting the primary DNS server to the static IP of the rock64. Hit Apply. It will take time for changes to take affect and this should be exemplified by a progress bar or something similar.

You are technically finished at this point. You may want to change the dashboard admin password to something less confusing than what is shown on the last page of the wizard. You can do this by opening another terminal window on your rock64, typing this command

pihole -a -p and entering your new password.

If you have the LCD screen that came with the bundle, you can follow the following steps to implement a script I wrote that will hit your PiHole’s API and print out stats like how many ads were blocked today, how many unique domains were blocked, and other interesting info to the LCD screen. If you have a different LCD screen, YMMV.

Step 5 – Setup LCD Screen to Print PiHole Stats:

Your LCD screen should be lit blue with white boxes when the rock64 is plugged in. If it is not, you may need to open the case and check the connections.

In a new terminal window on your Rock64, we are going to install pip3 and a few python packages. First, log in as root with the su command. Once logged in, execute these commands one line at a time:

cd
sudo apt-get update && apt-get upgrade
sudo apt-get install python3-pip
sudo apt-get install python-rpi.gpio
pip3 install RPLCD
pip3 install smbus2 
pip3 install pytz

 You may need to follow on screen prompts for the commands above, if they all worked successfully, you should be good to go.

You can now clone the python script that I wrote to pull data from your PiHole’s API and display it on the LCD screen by executing the following command:

git clone https://github.com/domdit/pihole_print_stats.git .

I will explain some quirks about the code below. First, let’s set the script up so it runs in the background whenever you boot the os. Open up cron with the following command:

export VISUAL=nano; crontab -e

and after the commented out lines, please add this line:

@reboot python3 ~/pihole_print_stats/print_stats.py &

This specifies that when rebooted, run this python script with python3 in the background (denoted by the & at the end of the line).

You can now reboot the Rock64 to check if the screen is outputting data with the following command:

sudo reboot

Final Thoughts:

Despite scouring the internet to figure out how to integrate this LCD screen, this was a pretty simple project. To be honest, I did not learn much of the code behind it and I would like to understand more about instantiating these LCD screens with more verbose settings than what I did in the code, which was to just use the model number of the backpack that came with the screen.  

I would like to try and write a script to automatically ssh into the rock64, add a message to the queue of things being printed, and resume printing the data. Not sure of the practicality of this, but seems like an interesting task.

Single Board Computing
linux, RockPi64, piHole