Skip to content

Lightweight Container to be used in conjunction with a Pi-hole instance to sync the DNS records of Cloudflare DNS to Pi-hole local DNS.

License

Notifications You must be signed in to change notification settings

fire1ce/pihole-cloudflare-dns-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pihole-cloudflare-dns-sync

Build License: GPL v3 Docker Pulls Docker Stars https://3os.org Contribution is Welcome

Description

Lightweight Container image based on python:3.9.13-alpine to be used in conjunction with a Pi-hole instance to sync the DNS records from Cloudflare DNS Service to Pi-hole local DNS.

Supports

  • A records
  • CNAME records
  • Any type of Pi-hole instance

Requirements

  • Cloudflare API Readonly Token
  • Pi-hole instance

Creating a Cloudflare API token

To create a CloudFlare API token for your DNS zone go to https://dash.cloudflare.com/profile/api-tokens and follow these steps:

  1. Click Create Token
  2. Select Create Custom Token
  3. Provide the token a name, for example, example.com-dns-zone-readonly
  4. Grant the token the following permissions:
    • Zone - DNS - Read
  5. Set the zone resources to:
    • Include - Specific Zone - example.com
  6. Complete the wizard and use the generated token at the CLOUDFLARE_API_TOKEN variable for the container

Parameters

Parameter Description Default Type Required
CLOUDFLARE_API_TOKEN Cloudflare API Token change_me string Yes
CLOUDFLARE_DOMAIN Cloudflare Domain example.com string Yes
EXCLUDE_PROXIED_RECORDS Exclude Proxied Records yes string Yes
PIHOLE_HOST Pi-hole hostname/IP 123.123.123.123 string Yes
PIHOLE_PORT Pi-hole port 80 integer Yes
USE_HTTPS http/https for pihole no string Yes
PIHOLE_PASSWORD Pi-hole password change_me string Yes
RUN_EVERY Run very x minute 5 integer Yes

Usage

Docker run example:

docker run -d \
  --name pihole-cloudflare-dns-sync \
  -h pihole-cloudflare-dns-sync \
  --restart always \
  -v /etc/timezone:/etc/timezone:ro \
  -v /etc/localtime:/etc/localtime:ro \
  -e CLOUDFLARE_API_TOKEN=cloudflare_secret_dns_zone_api_token \
  -e CLOUDFLARE_DOMAIN=example.com \
  -e EXCLUDE_PROXIED_RECORDS=yes \
  -e PIHOLE_HOST=123.123.123.123 \
  -e PIHOLE_PORT=80 \
  -e USE_HTTPS=no \
  -e PIHOLE_PASSWORD=secret \
  -e RUN_EVERY=1 \
  -e PUID=1000 \
  -e PGID=1000 \
fire1ce/pihole-cloudflare-dns-sync

Docker compose example:

version: '3'

services:
  pihole-cloudflare-dns-sync:
    image: fire1ce/pihole-cloudflare-dns-sync
    container_name: pihole-cloudflare-dns-sync
    hostname: pihole-cloudflare-dns-sync
    restart: always
    network_mode: bridge
    volumes:
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - CLOUDFLARE_API_TOKEN=cloudflare_secret_dns_zone_api_token
      - CLOUDFLARE_DOMAIN=example.com
      - EXCLUDE_PROXIED_RECORDS=yes
      - PIHOLE_HOST=123.123.123.123
      - PIHOLE_PORT=80
      - USE_HTTPS=no
      - PIHOLE_PASSWORD=secret
      - RUN_EVERY=1
      - PUID=1000
      - PGID=1000

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details