Home Pi-hole a blackhole for ads
Post
Cancel

Pi-hole a blackhole for ads

Pi-hole is a Linux network-level advertisement and Internet tracker blocking application which acts as a DNS sinkhole and optionally a DHCP server, intended for use on a private network. It is designed for low-power embedded devices with network capability, such as the Raspberry Pi, but can be installed on any Linux machine as well as in Docker. Pi-hole has the ability to block traditional website advertisements as well as advertisements in unconventional places, such as smart TVs and mobile operating system advertisements.

Depemdemcies

For everything to work out you will need to make sure that you have the following requirements:

If this is the case, we can carry on creating the pi-hole service.

It is recomended to clone the GitHub repo home-lab for the most up to date configuration of this service.

Setting up pi-hole container

Create a .env file and copy the data below into it. Make sure to change the CHANGE-ME values to your needed values:

1
2
3
4
#.env for pihole

HOST_IP=CHANGE-ME   # IP of the hosts IP-address where the container is running on. For example 192.168.1.200
WEB_PW=CHANGE-ME    # The password for the web-ui of pi-hole


Create a docker-compose.yml in the same directory as the .env file and copy the data below into it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
version: '3.9'

volumes:
  data: {}
  dnsmasq: {}

services:
  pihole:
    image: pihole/pihole:latest
    container_name: pihole
    restart: always
    ports:
      - ${HOST_IP}:53:53/tcp
      - ${HOST_IP}:53:53/udp
      - ${HOST_IP}:67:67/udp             # Optional for DHCP
      - ${HOST_IP}:8080:80/tcp           # Change variable to 127.0.0.1 if you want to use rev. proxy on the host
    dns:
      - 127.0.0.1
      - 9.9.9.9
    volumes:
      - data:/etc/pihole
      - dnsmasq:/etc/dnsmasq.d
      - /etc/localtime:/etc/localtime:ro
    cap_add:
      - NET_ADMIN
    environment:
      ServerIP: ${HOST_IP}
      TZ: 'Europe/Berlin'
      DNS1: 9.9.9.9
      DNS2: 1.1.1.1
      WEBPASSWORD: ${WEB_PW}

Managing the compose stack

The following commands should be run in the same directory as the docker compose file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Start the compose stack
# ---
sudo docker compose up -d

# Stop the compose stack
# ---
sudo docker compose down

# Rebuild / restart the compose stack
# ---
sudo docker compose up -d --force-recreate

# View the compose stack logs
# ---
sudo docker compose logs portainer

Post-install

Once the installer has been run, you will need to configure your router to have DHCP clients use Pi-hole as their DNS server which ensures that all devices connecting to your network will have content blocked without any further intervention.

If your router does not support setting the DNS server, you can use Pi-hole’s built-in DHCP server; be sure to disable DHCP on your router first (if it has that feature available).

As a last resort or for troubleshooting purpeses, you can manually set each device to use Pi-hole as their DNS server.


⚙️ If you see something that needs to be fixed, this documentation is open source! Feel free to open an issue here.

⭐ If you enjoied the post I would appreciate a star on GitHub

This post is licensed under CC BY 4.0 by the author.