← Back to Cyber ← Volver a Cyber

Cyber · Homelab

Network-Wide Ad and Tracker Blocking with Pi-hole on a Raspberry Pi Bloqueo de anuncios y rastreadores en toda la red con Pi-hole en una Raspberry Pi

Este artículo solo está disponible en inglés.

Overview

I turned a Raspberry Pi into a DNS sinkhole that filters ads, trackers, and known malicious domains for every device on my network, with no software installed on each device. I also set it up to work with a travel router, so the filtering follows me beyond my home network.

Later I added a live status display on an ESP32 and turned an old HP EliteDesk into a home file server. Those builds are covered further down.

What it does

Every time a device visits a website, it first asks a DNS server to translate the name (like google.com) into an IP address. Normally that server is your ISP’s or a public one like Google’s.

With Pi-hole in place, the flow looks like this:

  1. A device asks the Pi-hole for the IP of a domain.
  2. If the domain is on a blocklist (ad networks, trackers, malware hosts), Pi-hole answers with a dead-end response and it never loads.
  3. If the domain is good, Pi-hole forwards the request to an upstream resolver (Cloudflare, Quad9, etc.) and returns the real answer.

Benefits:

Hardware and software

Step 1: Flash and prepare the Raspberry Pi

sudo apt update && sudo apt full-upgrade -y

Step 2: Give the Pi a static IP

DNS clients need to find the Pi-hole at the same address every time. If its IP changes, every device on the network loses DNS. There are two ways to do this:

I assigned a static address (for example, 192.168.1.50) outside the router’s normal DHCP pool.

Lesson learned: the MAC address changed after reimaging

After reimaging the Pi, my router showed a new MAC address, which broke the reservation. A Pi has separate MACs for Ethernet (eth0) and Wi-Fi (wlan0), and newer Raspberry Pi OS versions using NetworkManager can randomize the Wi-Fi MAC. Running ip link shows the real values. The fixes:

sudo nmcli connection modify "YourWiFiName" 802-11-wireless.cloned-mac-address permanent

Step 3: Install Pi-hole

Run the official installer:

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

During setup, I:

Afterward, I set the admin password with pihole setpassword and logged in to the web dashboard at http://<pi-ip>/admin.

Important: the upstream DNS setting (Settings → DNS) is where Pi-hole sends its questions. It should never point to the Pi-hole itself or, generally, to the router.

Step 4: Point the network at the Pi-hole

Running Pi-hole doesn’t protect anything until devices actually use it. The router needs to hand out the Pi-hole’s IP as the DNS server to every client.

Lesson learned: the router’s direction matters

My first attempt didn’t work because I thought about it backwards. The router points to the Pi-hole, not the other way around. Also, many routers have separate WAN/Internet DNS and DHCP/LAN DNS fields. The WAN one only affects the router itself, while the DHCP/LAN one is what gets handed to clients.

If a router (often ISP-provided) won’t let you change DHCP DNS, the fallback is to disable the router’s DHCP server and enable DHCP in the Pi-hole (Settings → DHCP) so it controls everything.

Step 5: Refresh the clients

Devices keep their old DNS until their DHCP lease renews. To force it:

Step 6: Verify it works

Step 7: Extending it to a travel router

My travel router/repeater was handing out its own DNS settings, so I removed all of them and set only the Pi-hole’s IP as the DNS server, with the option to override DNS for all connected clients.

There was one catch. The travel router creates its own subnet (for example, 192.168.8.x) separate from the home network (192.168.1.x), and Pi-hole ignores queries from outside its local subnet by default. The fix is in the Pi-hole: Settings → DNS → Interface settings → Permit all origins. This is safe as long as the Pi-hole is not exposed to the internet.

Two side effects to note:

Step 8: Blocklists and allowlists

In the web dashboard under Domains (and Lists), you can add a blocklist or allowlist from a URL, such as a list maintained on GitHub, or type in individual domains yourself.

Steven Black’s list is enabled by default, which covers a good portion to start with, and there are plenty of community lists worth skimming.

The more you add to the blocklist, the higher the chance that someone on the network complains that a site or app is broken. Add aggressively, but keep the allowlist handy.

Troubleshooting cheat sheet

SymptomLikely causeFix
No change after setting DNSEntered in WAN field, not DHCP/LANMove it to the DHCP/LAN DNS field
Device still shows old DNSOld DHCP leaseRenew lease or reconnect
Some ads still appearSecondary DNS set, hardcoded DNS, or DNS-over-HTTPS in the browserRemove secondary DNS, disable browser DoH
Pi-hole ignores some devicesDifferent subnetPermit all origins
Everything broke after reimagingNew MAC, so the reservation no longer matchesUpdate reservation or use Ethernet
Internet down entirelyPi-hole is offline or its IP changedCheck Pi power and IP

Security notes

Part 2: An ESP32 Pi-hole display

The hardware

Step 0: Will this project work with my hardware?

Before flashing anything, I inspected the project files. Three checks mattered:

Screen pinESP32 GPIO
VCC3V3
GNDGND
DIN (MOSI)23
CLK (SCK)18
CS5
DC27
RST33
BL (backlight)32

Step 1: Does the PC see the board?

The CP210x chip turns the ESP32’s UART into a USB serial port. Windows needs its driver, and then the board shows up in Device Manager → Ports (COM & LPT) as “Silicon Labs CP210x USB to UART Bridge (COMx)”. The flashing tool (esptool, installed by PlatformIO) finds the COM port itself.

Common failure: a charge-only USB cable. If the port never appears, swap cables before blaming drivers.

Step 2: Flashing

The included flash.bat creates a Python virtual environment, installs PlatformIO, downloads the ESP32 toolchain and libraries, then does two uploads:

The first run took over five minutes, almost all of it downloads. The log showed the chip as an ESP32-D0WD-V3, the COM port auto-detected, and “Hash of data verified” after each write. That line is your proof the bytes on the chip match the file you sent.

Mistake #1: “I don’t see the GIF anywhere”

Both stages printed SUCCESS, but I couldn’t find the GIF and assumed the upload failed. Two things were going on:

Lesson: “flash succeeded” and “I can see output” are different checkpoints. Verify the log first, then the hardware.

Mistake #2: Unlabeled wires and mismatched pin names

The display came with an 8-wire cable, and the ESP32 headers used labels like “IO23” while my instructions said “D23”. Both refer to GPIO 23. Always match the number.

Worse, I guessed the cable colors from Waveshare’s usual scheme (red for VCC, black for GND, and so on). The guess was wrong. The actual cable was:

Wire colorSignal
PurpleVCC
WhiteGND
GreenDIN
OrangeCLK
YellowCS
BlueDC
BrownRST
GreyBL

Lesson: wire colors are not a standard. Trust the labels printed on the board, and double-check power and ground before applying power. Reversing VCC and GND is the one mistake here that can destroy a part.

How the display actually works

Mistake #3: Wrong Pi-hole IP

The animation played, but the counters stayed at ---.

The first clue came from the router: the ESP32 appeared in the connected-devices list. That proved the Wi-Fi credentials were correct and the board was on the network, which cut the problem in half. The remaining suspects were the Pi-hole address and Pi-hole authentication.

I tried the Pi-hole’s API in a browser from another device. It failed, so the address was wrong. The firmware pointed at ...208; the Pi-hole was actually at ...209. One digit. I corrected the address, re-ran flash.bat, and the counters came alive with green status squares.

Why it works: Pi-hole v6 exposes a REST API. The ESP32 runs the networking in a separate task (so a slow HTTP request never freezes the animation), requests the summary stats over HTTP, parses the JSON with ArduinoJson, and updates the counters. If the Pi-hole has a web password set, the firmware must authenticate first. A wrong IP produces exactly the symptom I saw: everything looks healthy except the data.

Lesson: get the real IP from your router’s device list, then give the Pi-hole a DHCP reservation so it never moves.

Security notes for the display

Part 3: Turning an old PC into a file server

The plan: TrueNAS

My first idea was TrueNAS Community Edition. It’s free and built on ZFS. A few facts shaped what happened next:

My machine was an HP EliteDesk with a single 1 TB drive holding personal files, and I couldn’t add a second drive.

Mistake #4: Choosing the tool before checking the constraints

Installing TrueNAS on that one drive would have wiped the personal files and turned the entire disk into a boot drive with no room for storage. With only one drive, TrueNAS’s best features (redundancy, snapshots across a pool) also wouldn’t apply.

Decision: keep Windows and share a folder over SMB instead. It costs nothing, risks no data, and meets the actual goal: reach files from other devices on the network.

How Windows file sharing works

Windows file sharing uses the SMB protocol over TCP port 445. A client connects, authenticates with a username and password, and then Windows decides what that user may do. Three layers have to agree:

I used a dedicated local account just for network access, instead of my main login or an administrator account. That’s the principle of least privilege: if those credentials leak, the damage is limited to one folder.

Step 1: Prepare the machine

Step 2: Create the account and share

Create a local user with a password, create a folder, then share it with that user under Advanced Sharing → Permissions, and grant the same user rights on the Security tab.

Error: “An object named … cannot be found.” In the permissions picker, typing the username returned this. The picker was searching the wrong location, or the account didn’t exist yet. Fix:

Step 3: Connecting from another device

The sharing account is the identity that clients present when they connect. The server itself keeps running under your normal login. A test from the server’s own desktop isn’t meaningful, because it uses your own permissions and never exercises the share account. Always test from a second device.

The network test that narrowed everything down, from the client PC:

Test-NetConnection <server-ip> -Port 445

The result was TcpTestSucceeded : True. That one line ruled out the firewall, the Private-profile setting, and the Wi-Fi path in one go. From that point on, every remaining problem was authentication or permissions.

System error 1326, “user name or password is incorrect.” The server was reachable but rejected the credentials: an authentication failure. Fixes:

System error 5, “Access is denied.” This was the most instructive one. Error 1326 means the login failed. Error 5 means the login succeeded and the server then refused access. So progress had been made: the account and password were right, but authorization was failing.

My shared folder was on the Desktop. Folders inside a user profile are locked down to that user, so other accounts can be denied even when the share settings look correct. I rebuilt the share on a plain folder at the root of the drive (C:\NAS) and re-applied permissions. That led to two more detours:

After rebuilding the folder and share permissions, the connection finally worked:

net use \\<server-ip>\NAS /user:COMPUTERNAME\<account>

To be honest about the root cause: I never isolated exactly which single setting caused error 5. The likely culprits were the profile-folder permissions or share/NTFS permissions that hadn’t been applied correctly, and what cured it was starting clean on a root-level folder with explicit permissions on both layers.

Step 4: Using it from other devices

Error cheat sheet

SymptomLayerWhat it meansFix
Counters show ---, ESP32 visible on routerApplicationWi-Fi fine, wrong Pi-hole address or authCorrect the IP, add the password if needed, re-flash
”SUCCESS” but no GIF visibleExpectationGIF is inside ESP32 flash, no screen attachedWire the screen
”Object cannot be found” in the share pickerAccount lookupWrong search location or account missingnet user, then Locations → PC name
TcpTestSucceeded : TrueNetworkPort 445 reachableLook at login and permissions next
System error 1326AuthenticationWrong username or passwordUse PCNAME\user, simple password
System error 5AuthorizationLogin OK, access refusedMove to a root-level folder, set both share and NTFS permissions
icacls “cannot find the file”FilesystemFolder doesn’t existmkdir, then dir to confirm
icacls “Invalid parameter”Shell parsingPowerShell mangled the syntaxUse cmd, quote the argument, or use the GUI

Hardening and reliability checklist

Takeaways

← Back to Cyber ← Volver a Cyber