Skip to content

Instantly share code, notes, and snippets.

@simonwhitaker
Created June 4, 2019 22:05
Show Gist options
  • Save simonwhitaker/d200b0641ee386db5102339a1c6fbd64 to your computer and use it in GitHub Desktop.
Save simonwhitaker/d200b0641ee386db5102339a1c6fbd64 to your computer and use it in GitHub Desktop.

Setting up Pi-hole on Raspbian Stretch

Prepare your Pi

First off, you need a Raspberry Pi running the latest version of Raspbian ("Stretch"). If you don't already have a Pi, I really like this kit for £49 from Amazon. Once you have your Pi, grab the latest copy of Raspbian Stretch Lite and flash it to an SD card using Etcher. (That kit on Amazon comes with an SD card.)

Enable SSH

With the SD card still attached to your computer, create a file in the root of the SD card called ssh. The contents can be blank. On a Mac, you can do this easily in the Terminal app:

ls /Volumes
touch /Volumes/[VOLUME NAME HERE]/ssh

Replace [VOLUME NAME HERE] with the name of your Pi's SD card. It's probably boot.

Connect to the Pi

Connect your Pi to your router with an ethernet cable and plug in its power. Give it a minute to boot up, then look in your router's admin panel to find the Pi's IP address. (On my router I can see all the IP addresses that have been allocated using DHCP, and one of those was associated with a hostname of "raspberrypi". Easy.)

Now open the Terminal app again, and type:

ssh pi@[IP address of your Pi]

For example:

The password is raspberry.

When you connect to your Pi it will encourage you to set a new password. So go ahead and do that.

Give your Pi a static IP address

Your router is probably configured to allocate IP addresses automatically using DHCP, with all the IP addresses coming from a range (typically 192.168.1.50 onwards, 10.0.0.50 onwards, or similar). The addresses outside this range are usually free to be statically assigned to various bits and bobs on your network. Pick a free one.

Example: 192.168.1.5

Now SSH to your Pi, and type:

nano /etc/dhcpcd.conf

Scroll to the bottom and add the following at the end of the file, replacing 192.168.1.5 with the IP of your Pi, and 192.168.1.1 with the IP of your router.:

interface eth0
static ip_address=192.168.1.5/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

Save your changes with CTRL+O (oh, not zero), then reboot your Pi:

sudo reboot

Now you should be able to SSH to the new, static address. If not, try the old address. If the worst comes to the worst, re-flash your SD card and start again.

Install Pi-hole

ssh [IP of your Pi]
curl -sSL https://install.pi-hole.net | bash

Follow the prompts, accept all the defaults. Easy. Make a note of the admin password you get at the end of the installation.

Check it's working

Go to http://[IP of your Pi]/admin. If you see the Pi-hole UI, you're good to go.

Update your router

Go into the admin settings for your router, go to the DHCP section, remove the existing DNS servers and add the IP of your Pi.

Now, all the devices on your network will use your Pi for their DNS resolution, and Pi-hole will filter out all the ads. Sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment