I will be running pi-hole on Ubuntun 22.04. The problem is, port 53 is already in use by my host, so lets sort this out first.

Check if port 53 is in use

You can check out this article to learn more about stopping systemd-resolve, or follow the below: https://www.linuxuprising.com/2020/07/ubuntu-how-to-free-up-port-53-used-by.html

Run this command:

sudo lsof -i :53

Your output will look like this if it is in use

lsof output

We can see that port 53 is in use by systemd-resolve. systemd-resolve is bascially a DNS resolver that comes with Linux. In most cases, it can be stopped without any issues.

Now run this command and uncomment the 2 lines in the image:

sudo nano /etc/systemd/resolved.conf

Just uncomment the DNS line and the DNSStubListener line. Set DNS to any DNS server (like cloudflare, Google, or your router IP address) and set DNSStubListener to no

resolved.conf

Now run these 2 commands:


sudo rm /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

Now restart your device and run the lsof command again. You should now get no output when running that command.

Starting up pi-hole in docker

Now that port 53 is free, we can start our pi-hole docker container. I will be using docker compose. Make sure port 80 is available, otherwise just map it to another port like I did below.

Also don’t put your password in your docker compose file, rather use a .env file.

version: "3"
services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "8033:80/tcp"
    environment:
      TZ: "Africa/Johannesburg"
      WEBPASSWORD: 'xxx'
    volumes:
      - "/opt/homeassistant/pihole/pihole:/etc/pihole"
      - "/opt/homeassistant/pihole/dnsmasq.d:/etc/dnsmasq.d"
    restart: unless-stopped

Accessing and using pi-hole

You can access pi-hole using the IP of your Linux host the container is running on, and the port specified in your compose file like below:

http://192.168.xx.xx:8033/admin/

Lastly, select this setting according to pi-hole’s docker page: https://hub.docker.com/r/pihole/pihole

permit all origins under settings, dns