Coder Social home page Coder Social logo

dynamic-stall / pihole-cloudflared-docker Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 968 KB

Public repository describing the setup and deployment of Pi-hole and Cloudflared (Tunnel Client) using Docker Compose

Shell 100.00%
ad-blocker centos centos-stream cloudflare cloudflare-zero-trust cloudflared dns docker docker-compose docker-network docker-pi-hole https macvlan pi-hole pihole proxy-dns raspberry-pi dns-over-https

pihole-cloudflared-docker's Introduction

Pi-hole Ad Blocker + Cloudflare Tunnel Client via Docker Compose

* credit goes to apavamontri for original code (see: https://github.com/apavamontri/pi-hole-cloudflared-docker) *

BLUF: This project will allow you to use Docker Compose to run Pi-hole and Cloudflare Tunnel Client in tandem to achieve DNS-Over-HTTPS. Not to mention network-level ad blocking!


NOTE: If your use case is to block YouTube or Hulu ads... find another use case ๐Ÿ˜œ.


DISCLAIMER: This is an educational experience aimed at deepening one's understanding of networking and containerization. Pi-hole is open-source software licensed under the European Union Public License (EUPL), which allows for its free use and modification. Please refer to this link for trademark rules and brand guidelines. As always, use your best judgement and/or the Internet for guidelines on things you should and should not be doing with this software.


DISCLAIMER II: There are still updates I'd like to make to this repo and I will, in time. Who knows? I might scrap this whole thing and employ Terraform, instead...


Requirements

  • Docker Compose or Docker Desktop (Docker install scripts for RHEL/CentOS Stream 8-9, Pi OS, and macOS included in this repo)

  • Your pick of operating system, generally... (Windows installs will require WSL v1.2 or later) (macOS version 10.13 -- High Sierra -- and newer is what ChatGPT and Google Gemini reccommend) (Most flavors of Linux are supported, but Google is always your friend; I'm using CentOS Stream 9)

  • Preferably at least 4GB of RAM (2GB might work, but you likely won't be happy with it)

  • (OPTIONAL) Cloudflare Zero Trust account for enhanced DNS capabilities


Build Instructions

i. (OPTIONAL) Create/log into your Cloudflare account and Navigate to Zero Trust from the lefthand menu. Expand Gateway and select DNS Locations.


ii. (OPTIONAL) Click the blue Add a location button. Choose whichever name you'd like (this matters to no one but you), then click the Add IP button; this should auto-populate with your current public address.


iii. (OPTIONAL) Check the Set as Default DNS Location box and click Add location in the bottom-right.


iv. (OPTIONAL) Click on your newly created location under the Location name menu. Under Location details, record the two IPv4 addresses as well as the DNS over HTTPS URL. Save those three values for later. (Those IPv4 addresses are essentially your personal 1.1.1.1 and 1.0.0.1 with enhanced security options)

image


  1. Make sure Docker is running by entering the following command in the terminal:
docker --version

It should return something like this:

Docker version 20.10.21, build baeda1f

  1. You can change the configuration values of Pi-hole and Cloudflare Tunnel Client in the docker-compose.yml file. Port configs should generally be left as is, unless you have specific requirements based on your environment. IP address ranges can be left as is, as Docker will create the bridge network for you (check notes at the end of that file as well as the troubleshooting steps in one of the install-docker_* scripts for details on how to specify existing external networks). I advise you leave the CONTAINER names as is; another script relies on them being named, "pihole" and "cloudflared." HOSTNAME changes will affect nothing but the joy in your heart.


  1. To build the Docker containers, run build-pihole.sh:
sudo ./build-pihole.sh

This bash script will:

  • Ask for your intended Web Admin password (in 'silent mode' for added security; i.e., you won't see characters as you type).

  • Start Docker Compose (in daemon mode).

  • Build your containers to spec (successfully, one would hope).


  1. Run the following command to check basic stats for your newly erected containers:
docker container ls

If you see either container stuck in a Restarting state, something went wrong during the build ("This looks like a job for..." you). You can try re-composing (or restarting either stuck container) as a first troubleshooting step:

./reload-pihole.sh

<OR>

docker restart <container_name>

Pi-hole Web Admin UI

Once the Pi-hole Docker container has started, you can access Pi-hole's Web Admin UI at http://localhost:8061/admin.

pi-hole-web-admin-home


Enter the Web Admin password you set earlier.


If the password needs to be reset, run the following command, replacing <password> with... you intended password:

docker exec pihole pihole -a -p <password>
  • (Leaving <password> blank will remove the password requirement altogether.)

You can check the Upstream DNS Servers by navigating to Settings from the lefthand menu and selecting the DNS tab. You should see the IP address set for your Cloudflare Tunnel Client under Custom 1 (IPv4).

d-room dns scrnshot-markup


Network Configuration

This last and most important step depends on your network setup and deployment strategy.


  • NOTE: If you have your Pi-hole container up and running, but Cloudflared is still misbehaving, you can deploy the Pi-hole container on its own: simply change the DNS servers Pi-hole is using under Settings (see: Pi-hole Web Admin UI section). Set the two custom IPv4 addresses to the Cloudflare DNS addresses you recorded earlier <OR> use one of the preset DNS locations (I'd still recommend choosing Cloudflare's 1.1.1.1, if nothing else...).

  • Note: I could have mentioned firewall configurations earlier than now... I've given you more than either of us needs, so I'm gonna leave this up to your ingenuity (read: ability to perform Google searches).

    • The basic command (for Linux users) is:
     sudo firewall-cmd --add-port=<port_num>/<protocol> --permanent
    

    (where <port_num> is the port number, and <protocol> is the Transport-layer protocol: either tcp or udp; both for port 53)

    • ... followed by a:
    sudo systemctl reload firewalld

    (you're welcome... ๐Ÿ˜).

pihole-cloudflared-docker's People

Contributors

dynamic-stall avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.