pihole is a free and open-source network-wide ad blocker. Pi-hole acts as a DNS sinkhole to block ads and trackers network-wide, providing privacy and performance benefits
1. Prerequisites
2. Supported Operating Systems
This guide supports installation on:
3. Installation
RHEL/CentOS/Rocky Linux/AlmaLinux
# Install EPEL repository if needed
sudo dnf install -y epel-release
# Install pihole
sudo dnf install -y pihole
# Enable and start service
sudo systemctl enable --now pihole-FTL
# Configure firewall
sudo firewall-cmd --permanent --add-port=53/tcp
sudo firewall-cmd --reload
# Verify installation
pihole -v
Debian/Ubuntu
# Update package index
sudo apt update
# Install pihole
sudo apt install -y pihole
# Enable and start service
sudo systemctl enable --now pihole-FTL
# Configure firewall
sudo ufw allow 53
# Verify installation
pihole -v
Arch Linux
# Install pihole
sudo pacman -S pihole
# Enable and start service
sudo systemctl enable --now pihole-FTL
# Verify installation
pihole -v
Alpine Linux
# Install pihole
apk add --no-cache pihole
# Enable and start service
rc-update add pihole-FTL default
rc-service pihole-FTL start
# Verify installation
pihole -v
openSUSE/SLES
# Install pihole
sudo zypper install -y pihole
# Enable and start service
sudo systemctl enable --now pihole-FTL
# Configure firewall
sudo firewall-cmd --permanent --add-port=53/tcp
sudo firewall-cmd --reload
# Verify installation
pihole -v
macOS
# Using Homebrew
brew install pihole
# Start service
brew services start pihole
# Verify installation
pihole -v
FreeBSD
# Using pkg
pkg install pihole
# Enable in rc.conf
echo 'pihole-FTL_enable="YES"' >> /etc/rc.conf
# Start service
service pihole-FTL start
# Verify installation
pihole -v
Windows
# Using Chocolatey
choco install pihole
# Or using Scoop
scoop install pihole
# Verify installation
pihole -v
Initial Configuration
Basic Configuration
# Create configuration directory
sudo mkdir -p /etc/pihole
# Set up basic configuration
# See official documentation for detailed configuration options
# Test configuration
pihole -v
5. Service Management
systemd (RHEL, Debian, Ubuntu, Arch, openSUSE)
# Enable service
sudo systemctl enable pihole-FTL
# Start service
sudo systemctl start pihole-FTL
# Stop service
sudo systemctl stop pihole-FTL
# Restart service
sudo systemctl restart pihole-FTL
# Check status
sudo systemctl status pihole-FTL
# View logs
sudo journalctl -u pihole-FTL -f
OpenRC (Alpine Linux)
# Enable service
rc-update add pihole-FTL default
# Start service
rc-service pihole-FTL start
# Stop service
rc-service pihole-FTL stop
# Restart service
rc-service pihole-FTL restart
# Check status
rc-service pihole-FTL status
rc.d (FreeBSD)
# Enable in /etc/rc.conf
echo 'pihole-FTL_enable="YES"' >> /etc/rc.conf
# Start service
service pihole-FTL start
# Stop service
service pihole-FTL stop
# Restart service
service pihole-FTL restart
# Check status
service pihole-FTL status
launchd (macOS)
# Using Homebrew services
brew services start pihole
brew services stop pihole
brew services restart pihole
# Check status
brew services list | grep pihole
Windows Service Manager
# Start service
net start pihole-FTL
# Stop service
net stop pihole-FTL
# Using PowerShell
Start-Service pihole-FTL
Stop-Service pihole-FTL
Restart-Service pihole-FTL
# Check status
Get-Service pihole-FTL
Advanced Configuration
See the official documentation for advanced configuration options.
Reverse Proxy Setup
nginx Configuration
upstream pihole_backend {
server 127.0.0.1:53;
}
server {
listen 80;
server_name pihole.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name pihole.example.com;
ssl_certificate /etc/ssl/certs/pihole.example.com.crt;
ssl_certificate_key /etc/ssl/private/pihole.example.com.key;
location / {
proxy_pass http://pihole_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Apache Configuration
<VirtualHost *:80>
ServerName pihole.example.com
Redirect permanent / https://pihole.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName pihole.example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/pihole.example.com.crt
SSLCertificateKeyFile /etc/ssl/private/pihole.example.com.key
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:53/
ProxyPassReverse / http://127.0.0.1:53/
</VirtualHost>
HAProxy Configuration
frontend pihole_frontend
bind *:80
bind *:443 ssl crt /etc/ssl/certs/pihole.pem
redirect scheme https if !{ ssl_fc }
default_backend pihole_backend
backend pihole_backend
balance roundrobin
server pihole1 127.0.0.1:53 check
Security Configuration
Basic Security Setup
# Set appropriate permissions
sudo chown -R pihole:pihole /etc/pihole
sudo chmod 750 /etc/pihole
# Configure firewall
sudo firewall-cmd --permanent --add-port=53/tcp
sudo firewall-cmd --reload
# Enable SELinux policies (if applicable)
sudo setsebool -P httpd_can_network_connect on
Database Setup
See official documentation for database configuration requirements.
Performance Optimization
System Tuning
# Basic system tuning
echo 'net.core.somaxconn = 65535' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_max_syn_backlog = 65535' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Monitoring
Basic Monitoring
# Check service status
sudo systemctl status pihole-FTL
# View logs
sudo journalctl -u pihole-FTL -f
# Monitor resource usage
top -p $(pgrep pihole)
9. Backup and Restore
Backup Script
#!/bin/bash
# Basic backup script
BACKUP_DIR="/backup/pihole"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_DIR/pihole-backup-$DATE.tar.gz" /etc/pihole /var/lib/pihole
echo "Backup completed: $BACKUP_DIR/pihole-backup-$DATE.tar.gz"
Restore Procedure
# Stop service
sudo systemctl stop pihole-FTL
# Restore from backup
tar -xzf /backup/pihole/pihole-backup-*.tar.gz -C /
# Start service
sudo systemctl start pihole-FTL
6. Troubleshooting
Common Issues
1. Service won't start:
# Check logs
sudo journalctl -u pihole-FTL -n 100
sudo tail -f /var/log/pihole/pihole.log
# Check configuration
pihole -v
# Check permissions
ls -la /etc/pihole
2. Connection issues:
# Check if service is listening
sudo ss -tlnp | grep 53
# Test connectivity
telnet localhost 53
# Check firewall
sudo firewall-cmd --list-all
3. Performance issues:
# Check resource usage
top -p $(pgrep pihole)
# Check disk I/O
iotop -p $(pgrep pihole)
# Check connections
ss -an | grep 53
Integration Examples
Docker Compose Example
version: '3.8'
services:
pihole:
image: pihole:latest
ports:
- "53:53"
volumes:
- ./config:/etc/pihole
- ./data:/var/lib/pihole
restart: unless-stopped
Maintenance
Update Procedures
# RHEL/CentOS/Rocky/AlmaLinux
sudo dnf update pihole
# Debian/Ubuntu
sudo apt update && sudo apt upgrade pihole
# Arch Linux
sudo pacman -Syu pihole
# Alpine Linux
apk update && apk upgrade pihole
# openSUSE
sudo zypper update pihole
# FreeBSD
pkg update && pkg upgrade pihole
# Always backup before updates
tar -czf /backup/pihole-pre-update-$(date +%Y%m%d).tar.gz /etc/pihole
# Restart after updates
sudo systemctl restart pihole-FTL
Regular Maintenance
# Log rotation
sudo logrotate -f /etc/logrotate.d/pihole
# Clean old logs
find /var/log/pihole -name "*.log" -mtime +30 -delete
# Check disk usage
du -sh /var/lib/pihole
Additional Resources
---
Note: This guide is part of the HowToMgr collection. Always refer to official documentation for the most up-to-date information.