Communitygithub.com

homelab-pihole-dns

安裝 Pi-hole、管理封鎖清單、設定 DNS-over-HTTPS、整合 DHCP,以及排解家庭網路中的 DNS 解析問題。當任務明確涉及 Pi-hole 時使用。

homelab-pihole-dns 是什麼?

此技能提供在家庭實驗室環境中部署、設定及維護 Pi-hole 的完整指引。Pi-hole 是一種網路層級的 DNS 廣告阻擋器,可執行於 Raspberry Pi 或任何 Linux 主機,自動為網路上所有裝置封鎖廣告與惡意軟體網域,無需在每台裝置上安裝瀏覽器擴充功能。技能涵蓋基於 Docker 的安裝方式(透過 docker-compose.yml)與裸機安裝(Raspberry Pi OS / Debian / Ubuntu),以及將路由器 DHCP 指向 Pi-hole 或讓 Pi-hole 本身擔任 DHCP 伺服器等網路指向方法。此外,還詳細說明如何管理 StevenBlack 與 Blocklist Project 等推薦的封鎖清單、使用 cloudflared 設定 DNS-over-HTTPS(DoH)以加密上游查詢、建立本機 DNS 記錄(如 nas.home.lan 和 grafana.home.lan),以及使用 pihole 命令進行疑難排解與記錄查詢。此技能特別強調反模式(例如:不設定靜態 IP 就安裝 Pi-hole、啟用 Pi-hole DHCP 前未先關閉路由器 DHCP)與最佳實務,適合管理自家網路 DNS 基礎架構的使用者。支援的平台包含 Docker、Raspberry Pi OS、Debian、Ubuntu。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/homelab-pihole-dns

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Homelab Pi-hole DNS

Pi-hole 是一種網路層級的 DNS 廣告阻擋器,可在 Raspberry Pi 或任何 Linux 主機上執行。 您網路上所有裝置會自動獲得廣告與惡意軟體網域封鎖功能,無需安裝瀏覽器擴充功能。

使用時機

  • 在 Raspberry Pi 或 Linux 主機上安裝 Pi-hole
  • 將 Pi-hole 設定為家庭網路的 DNS 伺服器
  • 新增或管理封鎖清單
  • 設定 DNS-over-HTTPS(DoH)上游解析器
  • 建立本機 DNS 記錄(例如 nas.home.lan、pi.home.lan)
  • 排解安裝 Pi-hole 後部分裝置無法上網的問題
  • 配合或取代 DHCP 執行 Pi-hole

Pi-hole 運作原理

運作流程(未使用 Pi-hole):
  裝置 → 請求 ads.tracker.com → ISP DNS → 真實 IP → 廣告載入

使用 Pi-hole:
  裝置 → 請求 ads.tracker.com → Pi-hole DNS → 封鎖(回傳 0.0.0.0)→ 無廣告

所有 DNS 查詢都會先經過 Pi-hole。
Pi-hole 會比對封鎖清單。
被封鎖的網域回傳空回應 — 廣告/追蹤器永不載入。
允許的網域則會被轉發到您的上游解析器(Cloudflare、Google 等)。

安裝

Docker(建議)

Docker 是安裝 Pi-hole 最簡單的方式,可讓更新和備份變得簡單直觀。

# docker-compose.yml
services:
  pihole:
    image: pihole/pihole:<pinned-release-tag>
    container_name: pihole
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "80:80/tcp"          # Web 管理介面
    environment:
      TZ: "America/New_York"
      WEBPASSWORD: "${PIHOLE_WEBPASSWORD}"   # 透過 .env 檔案或 secret 設定
      PIHOLE_DNS_: "1.1.1.1;1.0.0.1"
      DNSMASQ_LISTENING: "all"
    volumes:
      - "./etc-pihole:/etc/pihole"
      - "./etc-dnsmasq.d:/etc/dnsmasq.d"
    restart: unless-stopped
    cap_add:
      - NET_ADMIN              # 僅在 Pi-hole 提供 DHCP 服務時需要

在部署前,將 <pinned-release-tag> 替換為當前的 Pi-hole 發行標籤。 對於長期執行的 DNS 基礎架構,請避免使用 latest,以便每次升級都經過審慎規劃與審查。

在 docker-compose.yml 旁邊的 .env 檔案中設定 PIHOLE_WEBPASSWORD,將其權限設為 600,並確保它不會被納入 Git 版本控制 — 請勿直接將密碼寫入 compose 檔案中。

透過以下網址存取 Web 管理介面:http://<pi-ip>/admin

裸機安裝(Raspberry Pi OS / Debian / Ubuntu)

安裝 Pi-hole 前需先設定靜態 IP。

# 步驟 1:指定靜態 IP(在 Pi OS 上編輯 /etc/dhcpcd.conf)
sudo nano /etc/dhcpcd.conf
# 在檔案底部新增:
interface eth0
static ip_address=192.168.3.2/24
static routers=192.168.3.1
static domain_name_servers=192.168.3.1

# 步驟 2:執行前先下載並檢視安裝程式。
# 建議優先使用 Pi-hole 針對您的作業系統/版本所提供的套件或安裝程式路徑。
curl -sSL https://install.pi-hole.net -o pi-hole-install.sh
less pi-hole-install.sh   # 執行前先檢查內容

# 步驟 3:執行
bash pi-hole-install.sh

# 依循互動式安裝程式的指示:
# 1. 選擇網路介面(eth0 有線網路 — 建議)
# 2. 選擇上游 DNS(Cloudflare 或保留預設值 — 之後可修改)
# 3. 確認靜態 IP
# 4. 安裝 Web 管理介面(建議)
# 5. 記下最後顯示的管理員密碼

將您的網路指向 Pi-hole

# 方法 1:在路由器 DHCP 設定中更改 DNS(建議)
  路由器管理 UI → DHCP 設定 → DNS 伺服器
  主要 DNS:192.168.3.2(Pi-hole IP)
  次要 DNS:若需嚴格封鎖則留空,或使用第二台 Pi-hole。
              在佈署期間,使用公用備援(例如 1.1.1.1)可提高可用性,
              但用戶端可能會查詢它,導致封鎖被繞過。

  所有裝置在下次 DHCP 續約時會自動取得 Pi-hole 作為 DNS。
  強制續約:重新連線 Wi-Fi;在 Linux 上執行 'sudo dhclient -r && sudo dhclient'

# 方法 2:個別裝置 DNS(在全面佈署前用於測試很實用)
  Windows:控制台 → 網路介面卡 → IPv4 內容 → 手動設定 DNS
  macOS:系統設定 → 網路 → 詳細資訊 → DNS → 手動設定
  Linux:/etc/resolv.conf 或 NetworkManager

# 方法 3:Pi-hole 作為 DHCP 伺服器(取代路由器 DHCP)
  Pi-hole 管理介面 → 設定 → DHCP → 啟用
  請先停用路由器的 DHCP — 同一個網路上有兩台 DHCP 伺服器會導致衝突
  優點:主機名稱解析會自動生效(裝置會註冊其名稱)

封鎖清單管理

# Pi-hole 管理介面 → 廣告清單 → 新增廣告清單

# 建議的封鎖清單:
  https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
  # 預設 — 超過 200k 個網域

  https://blocklistproject.github.io/Lists/malware.txt
  # 惡意軟體網域

  https://blocklistproject.github.io/Lists/tracking.txt
  # 追蹤/遙測

# 新增清單後:
  工具 → 更新 Gravity(下載並編譯所有封鎖清單)

# 若某個不該被封鎖的網站被封鎖(誤判):
  Pi-hole 管理介面 → 白名單 → 新增網域
  範例:api.my-legitimate-service.com

# 即時查看哪些項目正在被封鎖:
  儀表板 → 查詢記錄(即時 DNS 查詢串流,顯示封鎖/允許狀態)

DNS-over-HTTPS 上游

DNS-over-HTTPS 會加密您的 DNS 查詢,讓您的 ISP 無法得知您解析哪些網站。

# 安裝 cloudflared(Cloudflare 的 DoH 代理程式)。
# 建議使用 Cloudflare 的套件儲存庫以進行自動簽署套件驗證。
# 若您直接下載二進位檔,請鎖定特定發行版本並驗證其 checksum。
CLOUDFLARED_VERSION="<pinned-version>"
curl -LO "https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/cloudflared-linux-arm64"
# 在安裝前,請從 Cloudflare 的發行說明中驗證 checksum/簽章。
sudo mv cloudflared-linux-arm64 /usr/local/bin/cloudflared
sudo chmod +x /usr/local/bin/cloudflared

# 建立 cloudflared 設定檔
sudo mkdir -p /etc/cloudflared
sudo tee /etc/cloudflared/config.yml << EOF
proxy-dns: true
proxy-dns-port: 5053
proxy-dns-upstream:
  - https://1.1.1.1/dns-query
  - https://1.0.0.1/dns-query
EOF

# 建立 systemd 服務
sudo cloudflared service install
sudo systemctl start cloudflared
sudo systemctl enable cloudflared

# 現在將 Pi-hole 指向本機 DoH 代理程式:
# Pi-hole 管理介面 → 設定 → DNS → 自訂上游 DNS
# 設定為:127.0.0.1#5053
# 取消勾選所有其他上游解析器

本機 DNS 記錄

讓您的服務可以透過名稱存取(例如 nas.home.lan、grafana.home.lan)。

網域名稱注意事項: .home.lan 在家庭實驗室中被廣泛使用且實際可行。 IETF 為本機用途保留的後綴是 .home.arpa(RFC 8375)— 若要遵循標準,請使用該後綴。 避免在 Pi-hole DNS 記錄中使用 .local,因為它會與 mDNS/Bonjour 衝突。

# Pi-hole 管理介面 → 本機 DNS → DNS 記錄

  網域               IP
  nas.home.lan        192.168.30.10
  pi.home.lan         192.168.30.2
  grafana.home.lan    192.168.30.3
  proxmox.home.lan    192.168.30.4

# 從網路上的任何裝置:
  ping nas.home.lan        → 192.168.30.10
  http://grafana.home.lan  → 您的 Grafana 儀表板

# 若需要子網域,請新增 CNAME:
  Pi-hole 管理介面 → 本機 DNS → CNAME 記錄
  網域:portainer.home.lan → 目標:pi.home.lan

疑難排解

# Pi-hole 封鎖了不該封鎖的內容
pihole -q example.com          # 檢查網域是否被封鎖以及屬於哪個清單
pihole -w example.com          # 立即加入白名單

# DNS 完全無法解析
pihole status                  # 檢查 pihole-FTL 是否正在執行
dig @192.168.3.2 google.com   # 直接對 Pi-hole 測試 DNS

# 重新啟動 Pi-hole DNS
pihole restartdns

# 檢查特定裝置的查詢記錄
pihole -t                      # 即時檢視所有查詢
# 或者在 Web 管理介面的查詢記錄中按用戶端過濾

# Pi-hole gravity 更新(重新整理封鎖清單)
pihole -g

反模式

# 不良:僅依賴一台 Pi-hole,沒有復原方案
# 若 Pi-hole 當機或 Pi 斷電,DNS 可能停止運作
# 良好:在設定過程中保留一個已記錄的路由器備援方案以進行回退
# 更佳:執行兩台 Pi-hole 以實現備援;若需嚴格封鎖,請避免使用公用備援 DNS

# 不良:未設定靜態 IP 就安裝 Pi-hole
# 若 Pi 取得新的 DHCP IP,所有裝置都會失去 DNS
# 良好:先設定靜態 IP,再安裝 Pi-hole

# 不良:啟用 Pi-hole DHCP 前未先關閉路由器的 DHCP
# 同一個網路上有兩台 DHCP 伺服器會發放衝突的 IP
# 良好:先停用路由器 DHCP,再啟用 Pi-hole DHCP

# 不良:從未更新 gravity(封鎖清單)
# 新的廣告和惡意軟體網域持續累積 — 過時的清單會漏掉它們
# 良好:排定每週 gravity 更新:pihole -g(或在「設定」→「API」中啟用)

最佳實務

  • 在安裝 Pi-hole 前,為 Pi 設定靜態 IP 或 DHCP 保留
  • 將 Pi-hole 用作主要 DNS;若需備援,請新增第二台 Pi-hole 而非公用解析器以實現嚴格封鎖
  • 使用 cloudflared 啟用 DoH(DNS-over-HTTPS)以加密上游查詢
  • 將 home.lan 設定為您的本機網域,並為所有服務建立 DNS 記錄
  • 偶爾檢視查詢記錄 — 被封鎖的查詢能讓您了解裝置正在做什麼

相關技能

  • homelab-network-setup
  • homelab-vlan-segmentation
  • homelab-wireguard-vpn

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能