|
| 1 | +# Pi-hole Setup Guide |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +- Docker and Docker Compose installed |
| 6 | +- Ubuntu Server (or compatible Linux distribution) |
| 7 | +- Router with configurable DNS settings |
| 8 | + |
| 9 | +## Installation Steps |
| 10 | + |
| 11 | +1. **Run the setup script:** |
| 12 | + ```bash |
| 13 | + ./setup.sh |
| 14 | + ``` |
| 15 | + This will: |
| 16 | + - Check Docker installation |
| 17 | + - Create `.env` file from template |
| 18 | + - Auto-detect and set `SERVER_IP` |
| 19 | + - Create necessary directories |
| 20 | + |
| 21 | +2. **Configure environment variables:** |
| 22 | + Edit the `.env` file created by the setup script: |
| 23 | + ```bash |
| 24 | + nano .env |
| 25 | + ``` |
| 26 | + - Set `PIHOLE_PASSWORD` to a strong password |
| 27 | + - `SERVER_IP` is automatically detected and set by the setup script |
| 28 | + - Adjust `TZ` to your timezone |
| 29 | + - Modify `DOMAIN` if needed (default: home.local) |
| 30 | + |
| 31 | + **Note:** If your server's IP changes, run `scripts/pihole/update-server-ip.sh` to update it automatically. |
| 32 | + |
| 33 | +3. **Start Pi-hole:** |
| 34 | + ```bash |
| 35 | + docker compose up -d |
| 36 | + ``` |
| 37 | + |
| 38 | + **Note:** Pi-hole uses `host` networking mode to see real client IP addresses in the query log. This allows you to identify which devices are making DNS queries, rather than all queries appearing to come from the Docker gateway. |
| 39 | + |
| 40 | +4. **Configure your router:** |
| 41 | + - Log into your router's admin interface |
| 42 | + - Find **DHCP Server Settings** (not just router DNS settings!) |
| 43 | + - Set **Primary DNS** to your server's IP address |
| 44 | + - Set **Secondary DNS** to `8.8.8.8` or `1.1.1.1` |
| 45 | + - Save and restart router if needed |
| 46 | + |
| 47 | + ⚠️ **Important:** You need to configure **DHCP DNS settings**, not just router DNS. These are often separate settings in router configuration. |
| 48 | + |
| 49 | +5. **Access Pi-hole admin:** |
| 50 | + - Open browser to `http://YOUR_SERVER_IP/admin` |
| 51 | + - Login with password from `.env` file |
| 52 | + |
| 53 | +6. **Verify it's working:** |
| 54 | + - See [Testing Pi-hole](#testing-pi-hole) below |
| 55 | + - Or run: `scripts/pihole/test-pihole.sh` |
| 56 | + |
| 57 | +## Testing Pi-hole |
| 58 | + |
| 59 | +### Quick Test Script |
| 60 | + |
| 61 | +Run the test script on your server: |
| 62 | +```bash |
| 63 | +./scripts/pihole/test-pihole.sh |
| 64 | +``` |
| 65 | + |
| 66 | +### Manual Testing |
| 67 | + |
| 68 | +#### Method 1: Check Pi-hole Dashboard |
| 69 | + |
| 70 | +1. **View Query Log:** |
| 71 | + - Go to `http://YOUR_SERVER_IP/admin` |
| 72 | + - Navigate to **Query Log** (left sidebar) |
| 73 | + - You should see DNS queries from devices on your network |
| 74 | + - Look for queries from different devices (phones, computers, etc.) |
| 75 | + |
| 76 | +2. **Check Statistics:** |
| 77 | + - Go to **Dashboard** in Pi-hole admin |
| 78 | + - Check the **Queries** counter - it should be increasing |
| 79 | + - Check **Blocked** counter - should show blocked ad/tracking domains |
| 80 | + - **Clients** should show devices using Pi-hole |
| 81 | + |
| 82 | +#### Method 2: Test DNS Resolution |
| 83 | + |
| 84 | +**On the server:** |
| 85 | +```bash |
| 86 | +# Test DNS resolution through Pi-hole |
| 87 | +dig @127.0.0.1 google.com |
| 88 | + |
| 89 | +# Or using nslookup |
| 90 | +nslookup google.com 127.0.0.1 |
| 91 | +``` |
| 92 | + |
| 93 | +**On a client device:** |
| 94 | +```bash |
| 95 | +# Linux/Mac |
| 96 | +dig @YOUR_SERVER_IP google.com |
| 97 | +nslookup google.com YOUR_SERVER_IP |
| 98 | + |
| 99 | +# Check what DNS your device is using |
| 100 | +# Linux |
| 101 | +cat /etc/resolv.conf |
| 102 | + |
| 103 | +# Mac |
| 104 | +scutil --dns | grep nameserver |
| 105 | + |
| 106 | +# Windows |
| 107 | +ipconfig /all | findstr "DNS Servers" |
| 108 | +``` |
| 109 | + |
| 110 | +#### Method 3: Test Ad-Blocking |
| 111 | + |
| 112 | +1. **Visit a test site with ads:** |
| 113 | + - Visit `https://www.forbes.com` or `https://www.cnn.com` |
| 114 | + - Check if ads are blocked (you may see blank spaces or "blocked" messages) |
| 115 | + |
| 116 | +2. **Test known ad domains:** |
| 117 | + - Visit `http://pi.hole` in your browser |
| 118 | + - You should see the Pi-hole block page |
| 119 | + - Or test: `http://doubleclick.net` (should be blocked) |
| 120 | + |
| 121 | +3. **Check blocked domains in Pi-hole:** |
| 122 | + - Go to **Query Log** in Pi-hole admin |
| 123 | + - Look for entries marked as **Blocked** (red) |
| 124 | + - Common blocked domains: `doubleclick.net`, `googleadservices.com`, `googlesyndication.com` |
| 125 | + |
| 126 | +#### Method 4: Verify Device DNS Settings |
| 127 | + |
| 128 | +**Check if devices are using Pi-hole DNS:** |
| 129 | + |
| 130 | +**Android:** |
| 131 | +- Settings → Wi-Fi → Long press your network → Modify network → Advanced → IP settings |
| 132 | +- Check DNS 1 and DNS 2 (should be your server IP) |
| 133 | + |
| 134 | +**iPhone/iPad:** |
| 135 | +- Settings → Wi-Fi → Tap (i) next to your network → Configure DNS |
| 136 | +- Should show your server IP |
| 137 | + |
| 138 | +**Mac:** |
| 139 | +```bash |
| 140 | +scutil --dns | grep nameserver |
| 141 | +``` |
| 142 | + |
| 143 | +**Linux:** |
| 144 | +```bash |
| 145 | +cat /etc/resolv.conf |
| 146 | +``` |
| 147 | + |
| 148 | +**Windows:** |
| 149 | +```cmd |
| 150 | +ipconfig /all |
| 151 | +``` |
| 152 | + |
| 153 | +### Expected Results |
| 154 | + |
| 155 | +✅ **Working correctly if:** |
| 156 | +- Query Log shows queries from multiple devices |
| 157 | +- Statistics show increasing query counts |
| 158 | +- Blocked counter shows blocked domains |
| 159 | +- DNS resolution works (google.com resolves) |
| 160 | +- Ad domains are blocked (doubleclick.net returns 0.0.0.0 or fails) |
| 161 | +- Devices show your server IP as DNS server |
| 162 | + |
| 163 | +❌ **Not working if:** |
| 164 | +- Query Log is empty (devices not using Pi-hole) |
| 165 | +- No blocked domains (ad-blocking not working) |
| 166 | +- DNS resolution fails |
| 167 | +- Devices show different DNS servers |
| 168 | + |
| 169 | +## Troubleshooting |
| 170 | + |
| 171 | +For detailed troubleshooting, see [Pi-hole Troubleshooting](./pihole-troubleshooting.md) |
| 172 | + |
| 173 | +**Quick fixes:** |
| 174 | + |
| 175 | +- **Can't access Pi-hole web interface:** |
| 176 | + - Check firewall: `sudo ufw allow 80/tcp` |
| 177 | + - Verify container is running: `docker compose ps` |
| 178 | + - Check logs: `docker compose logs pihole` |
| 179 | + |
| 180 | +- **Devices not using Pi-hole DNS:** |
| 181 | + - Run diagnostic: `./scripts/pihole/diagnose-pihole.sh` |
| 182 | + - See [Troubleshooting Guide](./pihole-troubleshooting.md) for router configuration |
| 183 | + |
| 184 | +- **DNS not resolving:** |
| 185 | + - Check Pi-hole logs: `docker compose logs pihole` |
| 186 | + - Verify upstream DNS servers in Pi-hole settings |
| 187 | + - Test DNS directly: `dig @YOUR_SERVER_IP google.com` |
| 188 | + - Check firewall: `sudo ufw allow 53/tcp && sudo ufw allow 53/udp` |
| 189 | + |
0 commit comments