Pi-hole on Raspberry Pi: complete Installation & Configuration Guide

Configurare noua (How To)

Situatie

Pi-hole is a network-wide ad blocker that acts as a DNS sinkhole. By running it on a Raspberry Pi, you can block ads and trackers for all devices on your network without needing browser extensions.

Solutie

1. Prerequisites

Hardware

  • Raspberry Pi (any model works, but Pi 3 or newer is recommended)

  • microSD card (8GB minimum, Class 10 recommended)

  • Power supply for the Raspberry Pi

  • Ethernet cable (recommended for stability) or Wi-Fi

  • Optional: Case for the Pi

Software

  • Raspberry Pi OS (Lite version recommended for headless setup)

  • SSH enabled (if setting up without monitor/keyboard)

2. Prepare the Raspberry Pi

Step 2.1 – Flash Raspberry Pi OS

  1. Download Raspberry Pi Imager:
    https://www.raspberrypi.com/software/

  2. Insert your microSD card and select:

    • OS: Raspberry Pi OS Lite (32-bit)

    • Storage: Your SD card

  3. Click Advanced Options (gear icon):

    • Set hostname (e.g., raspberrypi)

    • Enable SSH

    • Set username/password

    • Configure Wi-Fi (if not using Ethernet)

  4. Flash and eject the card.

Step 2.2 – Boot and Update

  1. Insert the microSD card into the Pi and power it on.

  2. Connect via SSH:

    ssh pi@<PI_IP_ADDRESS>
  3. Update packages:

    sudo apt update && sudo apt upgrade -y

3. Install Pi-hole

Pi-hole has a one-step installation script.

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

Step 3.1 – Installation Walkthrough

The installer will ask for several settings:

  1. Static IP address

    • Recommended to assign a static IP in your router’s DHCP settings.

    • Pi-hole can also set a static IP locally.

  2. Upstream DNS provider
    Common choices:

    • Cloudflare (1.1.1.1)

    • Google (8.8.8.8)

    • Quad9 (9.9.9.9)

    • Or a custom one.

  3. Blocklists

    • Pi-hole comes with a default blocklist; you can add more later.

  4. IPv4/IPv6

    • Enable both if your network supports IPv6.

  5. Admin Web Interface

    • Highly recommended — lets you monitor queries and add/remove blocklists easily.

  6. Logging and Privacy Mode

    • Choose how much detail you want stored.

4. Post-Installation Configuration

After installation, Pi-hole will give you:

  • Web interface address: http://<PI_IP_ADDRESS>/admin

  • Admin password (write this down)

Step 4.1 – Set Static IP

If not done in your router:

sudo nano /etc/dhcpcd.conf

Add lines:

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

Save & reboot:

sudo reboot

Step 4.2 – Access Web Dashboard

  1. Go to: http://<PI_IP_ADDRESS>/admin

  2. Log in using the password given at the end of installation.

  3. Check query logs and status.

Step 4.3 – Point Devices to Pi-hole

Two main ways:

  1. Router-level DNS (recommended)

    • In your router’s admin page, set Primary DNS to your Pi-hole’s IP.

    • All devices will use Pi-hole automatically.

  2. Device-level DNS

    • Set DNS manually in each device’s network settings.

Step 4.4 – Adding More Blocklists

In the Pi-hole dashboard:

  • Settings → Blocklists → Add URL
    Example:

    https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
  • Update gravity:

    pihole -g

5. Maintenance Commands

Command Description
pihole -g Update blocklists
pihole -up Update Pi-hole
pihole enable Re-enable blocking
pihole disable [seconds] Temporarily disable
pihole -t Live query log

6. Security Recommendations

  • Change the admin password:

    pihole -a -p
  • Keep Pi-hole and Raspberry Pi OS updated:

    sudo apt update && sudo apt upgrade -y
    pihole -up
  • Avoid exposing the Pi-hole web interface to the internet.

Tip solutie

Permanent

Voteaza

(26 din 49 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?