Setting Up Pi-hole with Docker for Network-Wide Ad Blocking

image_print

Introduction:
Pi-hole is a popular network-level ad blocker that helps you block advertisements at the DNS level. With Docker, you can easily deploy Pi-hole on your network for ad-free browsing on all your connected devices. In this guide, we’ll walk you through the process of setting up Pi-hole using Docker.

Step 1: Install Pi-hole with Docker

To install Pi-hole and run it in Docker, execute the following command:

docker run -d --name=pihole \
  -e TZ=Europe/Copenhagen \
  -e WEBPASSWORD=xxxxxxx \
  -e SERVERIP=192.168.0.224 \
  -e FTLCONF_LOCAL_IPV4=192.168.0.227 \
  -v pihole_data:/etc/pihole \
  -v pihole_dnsmasq:/etc/dnsmasq.d \
  -p 81:80 \
  -p 53:53/tcp \
  -p 53:53/udp \
  --net=host \
  --restart=unless-stopped \
  pihole/pihole:latest

Explanation of options used:

  • -d: Run the container in the background (detached mode).
  • --name=pihole: Assign the name “pihole” to the container for easy management.
  • -e TZ=Europe/Copenhagen: Set the timezone to “Europe/Copenhagen” inside the container.
  • -e WEBPASSWORD=xxxxxxx: Set a custom web admin password for Pi-hole. Replace “xxxxxxx” with your desired password.
  • -e SERVERIP=192.168.0.224: Set the IP address of the Docker host (Raspberry Pi) where Pi-hole will run. Replace “192.168.0.224” with your Raspberry Pi’s IP address.
  • -v pihole_data:/etc/pihole: Create a Docker volume named “pihole_data” and mount it to the “/etc/pihole” directory inside the container. This volume allows you to persist Pi-hole’s data and configurations.
  • -v pihole_dnsmasq:/etc/dnsmasq.d: Create a Docker volume named “pihole_dnsmasq” and mount it to the “/etc/dnsmasq.d” directory inside the container. This volume is used to customize DNS settings and blocklists.
  • -p 81:80: Map port 80 from the container to port 81 on the host system. This allows you to access Pi-hole’s web interface at http://localhost:81.
  • -p 53:53/tcp -p 53:53/udp: Map port 53 from the container to both TCP and UDP port 53 on the host system. This enables Pi-hole to handle DNS requests. Or “–net=host \” for local network install.
  • --restart=unless-stopped: Configure the container to automatically restart if it stops unexpectedly.
  • pihole/pihole:v5.6: Specifies the Docker image to use for running Pi-hole (version 5.6).

Step 2: Access Pi-hole Web Interface

Once the Pi-hole container is up and running, open a web browser and navigate to http://localhost:81. You will be directed to Pi-hole’s web interface. Use the custom web admin password you set in the Docker command to log in.

Congratulations! You have successfully deployed Pi-hole on your network using Docker. Your network devices will now benefit from network-wide ad blocking, providing a seamless and ad-free browsing experience.

Remember to configure your devices to use your Raspberry Pi’s IP address (192.168.0.224) as the DNS server to take advantage of Pi-hole’s ad-blocking capabilities.

Enjoy ad-free browsing and network-level ad blocking with Pi-hole and Docker! Happy browsing!

You may also like...