Setup Pi-hole
·2 mins
Vanilla installation #
- Setting up Pi-hole was really easy: https://docs.pi-hole.net/main/basic-install/
Docker, using macvlan #
The following allows you to setup Pi-hole with a new dedicated IP address alongside other services that are already running on port 80 on your machine.
version: '3.5'
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
cap_add:
- NET_ADMIN
networks:
pihole_network:
ipv4_address: 192.168.1.199 # New IP address that we'll assign to Pi-hole.
ports:
- 443/tcp
- 53/tcp
- 53/udp
- 67/udp
- 80/tcp
environment:
ServerIP: 192.168.1.199
TZ: 'America/Los_Angeles'
WEBPASSWORD: ""
volumes:
- '/home/pi/docker-stuff/etc-pihole:/etc/pihole'
- '/home/pi/docker-stuff/etc-dnsmasq.d:/etc/dnsmasq.d'
restart: unless-stopped
networks:
pihole_network:
driver: macvlan
driver_opts:
parent: eth0 # I got this from the output of `ifconfig`.
ipam:
config:
- subnet: 192.168.1.0/24
gateway: 192.168.1.1
ip_range: 192.168.1.192/28
Helpful resources on this:
- https://www.wundertech.net/how-to-set-up-pi-hole-on-openmediavault/ : this talks about how to do most of the above through the UI. (However, I found the docker-compose way easier to grok.)
- https://docs.pi-hole.net/docker/dhcp/#docker-pi-hole-with-a-macvlan-network -> https://tonylawrence.com/posts/unix/synology/free-your-synology-ports/ -> https://gitlab.com/tonyklawrence/files.tonylawrence.com/raw/master/synology/pihole/compose/docker-compose.yaml
Docker, using host networking #
- With macvlan, the host which is running pihole isn’t able to connect to 192.168.1.199. That breaks Tailscale.
- For the following approach to work, I had to do the following:
sudo sed -r -i.orig 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf
sudo systemctl restart systemd-resolved
- (See official documentation below.)
version: '3.5'
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
cap_add:
- NET_ADMIN
ports:
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
- "9001:80/tcp"
dns:
- 127.0.0.1
environment:
TZ: 'America/Los_Angeles'
WEBPASSWORD: ""
volumes:
- '/home/pi/docker-stuff/etc-pihole:/etc/pihole'
- '/home/pi/docker-stuff/etc-dnsmasq.d:/etc/dnsmasq.d'
restart: unless-stopped
Helpful resources:
- https://hub.docker.com/r/pihole/pihole
- https://github.com/pi-hole/docker-pi-hole#installing-on-ubuntu
Use pi-hole on the local network #
There are 2 ways of doing this:
- Use pi-hole as a DHCP server.
- On OpenWRT: go to Interfaces » Lan » DHCP Server » Advanced Settings, inside DHCP-Options enter value:
6,192.168.1.118
- For the host, put the following in the /etc/dhcpcd.conf file:
static domain_name_servers=192.168.1.199
- On OpenWRT: go to Interfaces » Lan » DHCP Server » Advanced Settings, inside DHCP-Options enter value:
- If you want to let the router remain as the DHCP server:
- In OpenWRT: Network -> Interfaces -> WAN/WAN6 -> Edit -> Advanced Settings -> Use custom DNS servers. Once for IPv4 and IPv6 each.
- For the host: put this in /etc/resolv.conf:
nameserver 127.0.0.1
On whether to use pi-hole as a DHCP server or not:
- If the host is a dedicated machine with a static IP (such as a bare-metal Raspberry Pi), use pi-hole as DHCP server. Otherwise, don’t - for e.g., if you installed pi-hole in an LXC container on Proxmox that relies on a DHCP server to get an IP address.
- See this: https://docs.pi-hole.net/main/post-install/