Set Up Raspberry Pi as DNS Server with Pi-hole: Step-by-Step Guide
To set up your Raspberry Pi as a DNS server with
Pi-hole, first install Pi-hole using its automated installer on your Raspberry Pi. Then configure your router or devices to use the Raspberry Pi's IP address as the DNS server, enabling network-wide ad blocking and DNS filtering.Syntax
The main command to install Pi-hole on Raspberry Pi is:
curl -sSL https://install.pi-hole.net | bash: Downloads and runs the Pi-hole automated installer script.- During installation, you select network interface, upstream DNS provider, and blocking lists.
- After installation, Pi-hole runs as a DNS server on your Raspberry Pi.
- Configure your router or devices to use the Raspberry Pi's IP as the DNS server.
bash
curl -sSL https://install.pi-hole.net | bashExample
This example shows how to install Pi-hole on Raspberry Pi and set it as your network DNS server.
1. Open terminal on Raspberry Pi.
2. Run the installer command.
3. Follow prompts to select interface and DNS provider.
4. After installation, note the Raspberry Pi's IP address.
5. Log in to your router and set the DNS server to the Raspberry Pi's IP.
6. Devices on your network will now use Pi-hole for DNS, blocking ads.
bash
curl -sSL https://install.pi-hole.net | bash # After installation, check IP address hostname -I # Example output: # 192.168.1.100 # Set router DNS to 192.168.1.100
Output
192.168.1.100
Common Pitfalls
Common mistakes when setting up Pi-hole DNS server:
- Not assigning a static IP to the Raspberry Pi, causing DNS to break if IP changes.
- Forgetting to update router DNS settings to point to Pi-hole.
- Using DHCP DNS settings that override Pi-hole, bypassing ad blocking.
- Not opening necessary ports or firewall rules blocking Pi-hole DNS traffic.
- Installing Pi-hole on an unsupported OS or outdated Raspberry Pi OS version.
Always set a static IP and verify network settings after installation.
bash
## Wrong: Using dynamic IP # Raspberry Pi IP changes, DNS fails ## Right: Set static IP sudo nano /etc/dhcpcd.conf # Add: interface eth0 static ip_address=192.168.1.100/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 127.0.0.1 sudo systemctl restart dhcpcd
Quick Reference
| Step | Command/Action | Description |
|---|---|---|
| 1 | curl -sSL https://install.pi-hole.net | bash | Run Pi-hole installer on Raspberry Pi |
| 2 | Set static IP | Configure Raspberry Pi to have a fixed IP address |
| 3 | Configure router DNS | Set router DNS server to Raspberry Pi IP |
| 4 | Verify Pi-hole dashboard | Access Pi-hole admin page at http:// |
| 5 | Test DNS | Use nslookup or ping to confirm DNS resolution through Pi-hole |
Key Takeaways
Install Pi-hole on Raspberry Pi using the official automated script.
Assign a static IP to your Raspberry Pi to ensure consistent DNS service.
Set your router or devices to use the Raspberry Pi's IP as their DNS server.
Verify Pi-hole is working by accessing its admin dashboard and testing DNS queries.
Avoid common mistakes like dynamic IPs and incorrect router DNS settings.