Thursday, September 12, 2019

A Black Hole for Web Ad's (Pi-Hole)


Pi-hole is a Linux network advertisement and Internet blocking application which acts as a DNS sinkhole (and optionally a DHCP server), intended for use on a private network.

It is designed for use on embedded devices with network capability, such as the Raspberry Pi, but it can be used on other machines running Linux and cloud implementations.

Pi-hole has the ability to block traditional website ads on your entire network as well as adverts in unconventional places, such as smart TVs and mobile ads found in apps and games.

Instead of running ad blockers in web browsers on multiple devices, Pi-Hole will block ads on ALL devices connected to your home network with no extra other software required on the individual machines/devices.

Pi-Hole provides

Network-wide protection
Instead of browser plugins or other software on each computer, install Pi-hole in one place and your entire network is protected.

Block in-app advertisements
Network-level blocking allows you to block ads in non-traditional places such as mobile apps and smart TVs, regardless of hardware or OS.

Improve network performance
Since advertisements are blocked before they are downloaded, network performance is improved and will feel faster.

Monitor statistics
The Web interface offers control of your Pi-hole and a central place to view statistics.  We also include an API for extending these stats.

Part of the web dashboard for Pi-Hole showing total DSN lookups, total lookups blocked (ads), and other great info.
I tested Pi-Hole first on a Beagle Bone Black mini computer board running the Debian OS for Beaglebone. The installation was a little more complicated due to preinstalled services on the Debian install that conflicted with the Pi-Hole installation. In the end I had a working device, but after a power cycle or restart I had to manually run a couple commands to get Pi-Hole running again (not optimum for a device you want to setup and trust it's always going to be working).

I was impressed enough from this trial that I just ordered a Raspberry Pi which Pi-Hole was designed to run on. Pi-Hole will run on the smallest Raspberry Pi Zero, but I opted for the business card sized Pi 3 B+ which has more power, ports and connections built right in so no need for added dongles or accessories.

I 3D printed a low profile case for the new Raspberry Pi on my Ender 3 printer from Creality. The Pi and Case together are smaller than a pack of cigarettes.

I can SSH into the Pi over the network for any remote tweaks, but I can also plug in a USB keyboard and mouse and connect to a monitor with an HDMI cable for a direct connect experience if needed.

To run Pi-Hole day to day the little Pi box just needs a power cord and network cable

Raspberry Pi 3 B+ in 3D printed slip case using black gloss PLA filament
Here's the installation notes I recorded for myself.
  • Download latest Raspian OS image (no desktop version, command line was all I needed)
  • Flash to SD card with Etcher for Windows
  • Mount SD card to Pi and boot
  • The default username on Raspbian is pi and the default password is raspberry.
  • I immediately changed the default password to my own secure one for home server devices.

---------------------------------------------------------------------
Options
  • open the PI’s configuration screen (in the terminal window) by typing:

sudo raspi-config

  • Various options in here were set or changed.
  • Hostname was changed to pi-hole
  • Location set to US
  • Keyboard set to 104 key US
  • Under advanced I expanded the file system on the 16GB SD card to use all space available
  • timezone, etc.
  • NOTE do not change the network option for 'predictable network interface names'. This must be OFF and not 'on'
  • click: Finish
  • select ‘YES‘ when it asks for a reboot

---------------------------------------------------------------------
Home Network Settings
  • Home router = 192.168.0.1
  • Router's DNS was normally set for DHCP from my ISP
  • Network clients used the IP of the router for DNS

New Home Network Settings required for Pi-Hole

  • Home router = 192.168.0.1 (same)
  • Pi-Hole device = 192.168.0.2 (new and available)
  • Router's DNS was changed to point to the Pi-Hole (192.168.0.2)
  • During the Pi-Hole installation I chose Cloudflare as the new external DNS service used by Pi-Hole for it's lookups. There are 9 choices total, all the top DNS services in the world.

Setting the Static IP on the Raspberry Pi

Start by editing the dhcpcd.conf file

sudo nano /etc/dhcpcd.conf

Changes made at the end of the file

interface eth0
static ip_address=192.168.0.2/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

Saved changes and reboot. 
Confirmed that the IP has changed after the reboot.

---------------------------------------------------------------------
One-Command Automated Install of Pi-Hole

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

The Pi-Hole installation is very easy and guided and there are tons of other tutorial sources online about what to chose for options. In many cases you can select the default option on almost every screen and it will work just fine.


---------------------------------------------------------------------