Pi Top Dashboard

Installing Pi-Hole

Used Equipment

  • Raspberry Pi Zero (Or any Raspberry Pi with network)
  • Pi Power Supply
  • SD card 4GB or more
  • Ethernet cable (optional when using wifi)

Pi Hole

PI-Hole is an Internet Adverts worst enemy, by comparing DNS requests against an ever expanding block list it reduces the amount of Ad traffic on webpages!
For the sake of this tutorial we will be connecting the pi via WIFI for those of you who want to connect via ethernet just ignore any parts to do with WIFI configuration.

So first things first we need a memory card flashed with the latest raspbian OS, I’m using a 16GB Micro SD but an 8GB should suffice just as well.
Now we are going to be using the Raspbian Lite ISO for this setup, there are a few reasons for this:

  • Smaller Footprint 1.3GB vs 4GB
  • Running Lite/Core requires less processing power making this build suitable for the Pi Zero
  • We do not need a GUI as the Pi-Hole configuration comes with a fantastic web interface.

So if you know how to flash your SD card go ahead and do that ready for the next step, and for those that don’t go ahead and read our SD card burning tutorial you want to follow the Balena Etcher section. Now we have the Card flashed, we are going to leave it in the pc whilst we make some small adjustments.

Adjustment 1:

We need to create a file called ssh, the latest versions of raspbian were modified to make running a headless system easier, what this means is that on boot raspbian will check the Boot folder for certain files and if they exist will load them into the main configuration. So in this case a file called ssh will cause the pi to enable ssh connections.

So to create the file what we are going to do is open the boot partition on the PI, go to view on the top bar and ensure that

installing pi hole

Now create a new text file called ssh, to do this right click, then ​New​, then ​Text Document.
Rename it ssh and delete the ​.txt​ at the end. Hit enter and you’ll get a message warning you of the file type change click
Yes​. Don’t worry we won’t break anything.

SSH file creation

Adjustment 2:

Now we need to prepare the PI to connect to our network when it boots. In order for us to auto connect the PI to the network we need to know the SSID and Password of the WiFi Network we want the PI connected to. (I will explain how to assign our PI a static IP later on)
Now if we know the above information we can begin;
Follow Adjustment 1 in creating a new file but instead of calling it ssh we want to call it ​wpa_supplicant.conf. Now right click and edit the file using Notepad, we want to copy the below template:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
    ssid="Your network name/SSID"
    psk="Your WPA/WPA2 security key"
    key_mgmt=WPA-PSK
}

Paste this template in your document changing the country from GB to your country code (Unless you are GB), Change SSID to match your wifi name, and PSK to the password for your wifi. When you’ve done this click save. Now we are ready to power on our Pi and connect into it. So go ahead insert the SD card into the PI and power on!

So just to clarify our previous steps the PI, upon first boot, will load the SSH and the wpa_supplicant files into the running config of the PI this will enable SSH and configure the wireless connectivity. Now that we are connected the PI will automatically be assigned an IP address via DHCP from your router, the first thing we are going to do before connecting to
the PI is to log on to the router and reserve the IP Address for the PI.

The reason we reserve the IP is so the PI will always be assigned the same address for when we need to access the web portal, don’t worry if you don’t have access to the router below i will show you how to set the IP Statically. To find your PI’s ip address without accessing the router use a tool like ​Advanced IP Scanner​ and look for Raspberry PI.

My personal router is a draytek Vigor, so what i do here won’t necessarily apply to your set up, do some research into your router settings to learn how to do this.

Fixed IP on router
IP List on router example

Under this option I can see all connected IP’s to my router, in my case I’ve created a separate SSID and VLAN for this with the ip range 192.168.1.xxx so as you can see above there are two addresses. By using command prompt and ipconfig I know the 192.168.1.10 address is my laptop so .11 must be the Raspberry PI. Double clicking that ip will add it to the Bind List and reserve that ip for that device every time it connects.

This tutorial has been writen using Putty, but we recommend you to use MobaXterm, You can see it at work in our Remote Acces Tutorial.

With that complete we can get to the good stuff!!!
Download an application called Putty from this link : ​Putty
Once downloaded open up the program and you’ll see an interface like this:

Putty Configuration

Type the Pi’s IP into the Host/Address box ensure SSH is checked and click ​Open​, you will get a box like below, click ​Yes​ :

Putty Security Alert

After that this a ssh console screen will appear.
The Login is ​pi ​type this and hit enter, then the password is ​raspberry ​hit enter again and the PI will log in.

Putty Console
Putty Console

Ok if you’ve got to this part well done your PI is configured correctly and we can now start with the really fun stuff:

Step 1 : ​ Change the Password


Type the command​ passwd​ in and this will prompt you to enter the current password, so enter ​raspberry ​and hit enter, the in will prompt you to change the password, choose something secure and press enter, it will ask you to confirm the password, do so and hit enter again.

Step 2: ​Install any Updates

Type ​sudo apt-get update​ then hit enter, let this run out and when it has finished type ​sudo apt-get upgrade ​and hit enter again. Whilst this command is running it will ask you if you wish to continue (y/n) type ​y​ and hit enter (If it prompts for a root password or a password for sudo, type your newly created password and hit enter)

Step 3: ​Installing Pi-Hole

Now we have a more secure setup and it’s up to date we can begin to pull down the packages and install Pi Hole.
Luckily the creators of Pi-Hole have made this super user friendly, we run a curl command to the install.pi-hole.net URL and
it instantly pulls down all the commands we need push these commands into bash (our command line) and it will run them. Here’s the command you need for this (Copy and paste it into your putty session then hit enter).

​ sudo curl -L install.pi-hole.net | bash

Follow the on-screen instructions and read carefully, i will guide you through the important bits so don’t worry 🙂 Now the first thing to note is that we haven’t called this from a root user account so you may think you’ve received an error message but dw if your screen looks like the image on the left wait and it will change to the one on the right.

Pi-Hole installation

Just follow the commands until you reach this screen:

Pi-Hole DNS Settings

Now this choice is up to you, i prefer google so i’m just going to use their DNS servers and hit enter.

Pi-Hole Block lists

Leave all these checked unless you want to create your block list from scratch, same on the next page.

Now on this page if you wish to assign the PI’s IP Statically instead of reserving it on your router, then you can. Just be careful that you are setting it to an unused ip address in your network, to double check you can use something like Advanced ip scanner​ to give you a rough idea of unused addresses.

If you want to set a static address click ​No, ​if you are happy with the current reserved ip then hit ​Yes​ and continue on to the next bit.

Static IP

If you clicked ​No​ then you now need to enter the IP Address you wish to give the PI, for me this is 192.168.1.2/24, the /24 denotes the size of your network for most users this is most likely /24, if however you’re doing this in a large scaled environment then check with the local network team.
Once you’ve entered the address click ​Ok.

IP Gateway

Next up is the default gateway, this would typically be the IP of the local router, however to be sure we can check. If your computer is on the same network as the PI open command prompt and type ​ipconfig ​or for linux ​ifconfig. Here you will be able to see your current ip and the ip of the default gateway. Copy the default gateway into the box above and hit ​Ok.
Confirm the settings and click ​Yes​.

Enable Web Interface

At the above box ensure​ On ​is checked and click ​Yes​, this will install the relevant files for the web interface on the PI.

Leave the next boxes as default and click ​Yes​ to all. After this the screen will flash back to the command line then back to the blue screen where it will begin installing all the required packages. You can keep an eye on the install using the progress bar on screen but for now sit back and enjoy.

Now at the end of the install you may find that the console session goes inactive this isn’t an issue just open putty again and reconnect. ​Remember​ if you set a static ip connect using that ip not the old DHCP Address.

Now keep an eye out for this box:

Installation Complete

This tells you the setup has completed successfully! Well done 😉
It also tells you how to access the admin page and the password to login to it so note these details down the click ​Ok.
So let’s go ahead and head to our admin console 🙂
Open your browser and type the URL given at the end of the installation to access the PI-Hole web Console.

Pihole Dashboard

Once you’re at the above page go to ​Login​ and type the password from the installation prompt earlier then hit enter. (​Note: this is randomly generated and should be different for everyone)

And we are almost done just a last bit of housekeeping, head back to your putty SSH session and run the following command to change the password to the Web console:

​pihole -a -p

Follow the console prompts and you are ​DONE!
Enjoy playing with your new PI-Hole Server!

Setting up your network

So we have set up Pi-Hole on our raspberry Pi, but how do we use it?
There are 2 options here, the first one is changing the DNS settings on your router and thus activating pi hole for your whole local network. The second option is to change all the DNS settings on all your internet connected devices.

As you can imagine, setting the DNS settings on your router will cost you less energy then setting it on all your devices. so lets get started on the router.

Router Settings

This step is only applicable when you have acces to your router, if not go to PC settings.

Lets login to your router. In most cases this will be 192.168.0.1 or something similat depending on your network settings. Open your flavoured browser and type in this IP addres, if you don’t get a login screen, or you don’t have admin acces jump to PC settings.
Once on you router go and locate your DNS settings (if you can change this) on my router it is located under Your modem.

DNS settings router

In the primary DNS type in the Static ip of your Pihole installation. you can chose any flavour for your secondary, mine is the backup DNS from Google.
Save it and have fun, you’ll see progress on your Pi-Hole Dashboard.

PC Settings

So since you got to this part you’ll probably don’t have acces to the router settings, or you don’t want to mess with them. Lets see how you can change your computer to use your custom DNS.

Windows

On windows you want to go to the controll panel (klick on the start button and then controll panel). When in the controll panel search for network center, open this.

Hoe de LAN-snelheid te vinden op Windows 10 - Tutorials voor ...

Click on either Ethernet of Wi-Fi next to connection at the right hand side. This will open up the status of your connection.
To go on you’ll need to be administrator of the PC, if you are not you’ll have to ask your system admin for the change.
Here you press the Properties button

Kan geen 1GBPS krijgen - Netwerken - GoT

Once you opend up the Properties you’ll find a list of all available components, search for IPv4 and click on properties once again

Blank network connection properties - Super User

This will finely open up the window we are looking for.

How to Configure a Static IPv4 Address in Windows 7 - Petri

Here you have 2 options, you set a static ip for your PC like in my setup AND specify the DNS servers, or you just specify the custom DNS servers.
Mark Use the following DNS server addresses, and enter your Pi hole DNS as preferred DNS server. On the Alternate DNS server i recoomend you enter a secondary DNS like the one from Google (either 8.8.8.8 or 8.8.4.4). When your Pi hole/Raspberry pi will freez of crash for some reason you’ll still have internet acces.

Linux

Unlike what you may find on the internet, you can’t just change the /etc/resolf.conf file as sugested in many places, this is because the resolvconf program might be installed.
As this is a Pi tutorial lets see how we can set the Pi’s DNS

NOTICE: do not use the pi that has the Pi-Hole installation on it.

Lets open a console on the pi or ssh into your pi. You can find how to ssh into the pi here.
Now that we are logged in lets head to /etc/dhcpcd.conf.

sudo nano /etc/dhcpcd.conf

Go to the bottom of this file and add following line, supstitude your pi’s ip with the first ip in the row.

static domain_name_servers=192.168.0.2 8.8.8.8

Save this file using ctr+X, Y and enter. cntr+X is the exit command. Since we changed something it will ask you if you want to save this file, on this question you answer with Y(es) and press enter to confirm.
When we have done this we like to restart the DHCP service and check if what we have done is realy changed the DNS settings. enter following command in the console.

sudo service dhcpcd restart
sudo nano /etc/resolv.conf

The first command restarts the dhcp deamon, the second opens the resolv.conf file and here we can check if what we have changed realy is in there.

Resolv.conf file

If you can see the correct nameservers in the resolv.conf file, you have succesfully set the DNS servers on the Pi.
Once set you’ll see that ifyou go and browse the internet many ad’s are blocked. you can see these blocked ad’s in pi hole.

Blocked domains

Pi-Hole blocks

So after a few minits, hours or days depending on your internet usage you can see a lot of blocking going on.
How did we ever live without?

Blocked domains

Leave a reply:

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.