Pi-hole 树莓派配置指南
概述
Pi-hole 是一个基于 DNS 的广告拦截器,装在树莓派等低功耗设备上,为整个局域网提供广告过滤服务。
适用场景
- 树莓派 3B/4B/5 作为 Always-on 家庭服务器
- 局域网内所有设备(手机、电脑、电视、IoT设备)广告拦截
- 无需公网IP,仅局域网即可运行
安装步骤
1. 安装
curl -sSL https://install.pi-hole.net | bash2. 上游 DNS 选择(国内推荐)
| DNS | 地址 | 推荐度 |
|---|---|---|
| 阿里 DNS | 223.5.5.5, 223.6.6.6 | ⭐⭐⭐⭐⭐ |
| 腾讯 DNSPod | 119.29.29.29 | ⭐⭐⭐⭐ |
| 114 DNS | 114.114.114.114 | ⭐⭐⭐ |
安装时若列表中没有阿里DNS,先随便选一个,装完进管理面板 → Settings → DNS → 自定义填入。
3. Privacy Mode
家用场景选 0(不隐藏),才能看到拦截统计和排查问题。隐私模式(1-3)是给企业/公共场合用的。
4. 路由器全局 DNS 设置
将路由器 DHCP 的 DNS 服务器设为树莓派 IP,备选设为公共 DNS(如 223.5.5.5),防止树莓派掉线导致全家断网。
常见问题
装到一半卡住
大概率是国外源下载慢。换国内源:
sudo tee /etc/apt/sources.list << 'EOF'
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-security main contrib non-free non-free-firmware
EOF
sudo apt update树莓派掉线了怎么办
路由器 DNS 设置主备模式:
- 主 DNS:树莓派 IP(192.168.x.x)
- 备 DNS:阿里 DNS 223.5.5.5
树莓派挂了,设备自动切到备 DNS,上网不受影响,只是广告过滤失效。