Use Cloudflare Gateway DNS/VPN to block ads, malware and tracking domains - free alternative to NextDNS, Pi-hole and Adguard

Overview

Cloudflare Gateway Pi-hole Scripts (CGPS)

Cloudflare Gateway Analytics screenshot

Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and network traffic based on your firewall policies. This is a collection of scripts that can be used to get a similar experience as if you were using Pi-hole, but with Cloudflare Gateway - so no servers to maintain or need to buy a Raspberry Pi!

About the individual scripts

  • cf_list_delete.js - Deletes all lists created by CGPS from Cloudflare Gateway. This is useful for subsequent runs.
  • cf_list_create.js - Takes an input.csv file containing domains and creates lists in Cloudflare Gateway
  • cf_gateway_rule_create.js - Creates a Cloudflare Gateway rule to block all traffic if it matches the lists created by CGPS.
  • cf_gateway_rule_delete.js - Deletes the Cloudflare Gateway rule created by CGPS. Useful for subsequent runs.

Features

  • Support for basic hosts files
  • Full support for domain lists
  • Automatically cleans up filter lists: removes duplicates, invalid domains, comments and more
  • Works fully unattended
  • Whitelist support, allowing you to prevent false positives and breakage by forcing trusted domains to always be unblocked.
  • Optional health check: Sends a ping request ensuring continuous monitoring and alerting for the workflow execution.

Usage

Prerequisites

  1. Node.js installed on your machine
  2. Cloudflare Zero Trust account - the Free plan is enough. Use the Cloudflare documentation for details.
  3. Cloudflare email, API key (NOT the API token), and account ID
  4. A file containing the domains you want to block - max 300,000 domains for the free plan - in the working directory named input.csv. Mullvad provides awesome DNS blocklists that work well with this project. A bash script that downloads recommended blocklists, get_recommended_filters.sh, is included.
  5. Optional: You can whitelist domains by putting them in a file whitelist.csv. You can also use the get_recomended_whitelist.sh Bash script to get the recommended whitelists.

Running locally

  1. Clone this repository.
  2. Run npm install to install dependencies.
  3. Copy .env.example to .env and fill in the values.
  4. If this is a subsequent run, execute node cf_gateway_rule_delete.js and node cf_list_delete.js (in order) to delete old data.
  5. If you're on Linux and haven't downloaded any filters yourself, use the get_recommended_filters.sh script to download recommended filter lists (about 250 000 domains).
  6. Run node cf_list_create.js to create the lists in Cloudflare Gateway. This will take a while.
  7. Run node cf_gateway_rule_create.js to create the firewall rule in Cloudflare Gateway.
  8. Profit!

Running in GitHub Actions

These scripts can be run using GitHub Actions so your filters will be automatically updated and pushed to Cloudflare Gateway. This is useful if you are using a frequently updated malware blocklist.

Please note that the GitHub Action downloads the recommended blocklists and whitelist by default. You can change this behavior by editing the file.

  1. Create a new empty, private repository. Forking or public repositories are discouraged, but supported - although the script never leaks your API keys and GitHub Actions secrets are automatically redacted from the logs, it's better to be safe than sorry.
  2. Create the following GitHub Actions secrets in your repository settings:
  • CLOUDFLARE_API_KEY: Your Cloudflare API key
  • CLOUDFLARE_ACCOUNT_ID: Your Cloudflare account ID
  • CLOUDFLARE_ACCOUNT_EMAIL: Your Cloudflare account email
  • CLOUDFLARE_LIST_ITEM_LIMIT: The maximum number of blocked domains allowed for your Cloudflare Zero Trust plan. Use 300000 for the free plan or if you're unsure.
  • PING_URL: /Optional/ The HTTP(S) URL to ping (using curl) after the GitHub Action has successfully updated your filters. Useful for monitoring.
  1. Create a new file in the repository named .github/workflows/main.yml with the contents of auto_update_github_action.yml found in this repository. The default settings will update your filters every week at 3 AM UTC. You can change this by editing the schedule property.
  2. Enable GitHub Actions in your repository settings.

DNS setup for Cloudflare Gateway

  1. Go to your Cloudflare Zero Trust dashboard, and navigate to Gateway -> DNS Locations.
  2. Click on the default location or create one if it doesn't exist.
  3. Configure your router or device based on the provided DNS addresses.

Alternatively, you can install the Cloudflare WARP client and log in to Zero Trust. This method proxies your traffic over Cloudflare servers, meaning it works similarly to a commercial VPN.

Why not...

Pi-hole or Adguard Home?

  • Complex setup to get it working outside your home
  • Requires a Raspberry Pi

NextDNS?

  • DNS filtering is disabled after 300,000 queries per month on the free plan

Cloudflare Gateway?

  • Requires a valid credit card
  • Limit of 300k domains on the free plan

a hosts file?

  • Potential performance issues, especially on Windows
  • No filter updates
  • Doesn't work for your mobile device
  • No statistics on how many domains you've blocked

License

MIT License. See LICENSE for more information.

Donations

If you would like to donate to support this project, you can do so via Liberapay - click the Sponsor button or see my GitHub profile for the link.

Comments
  • tutorial for github

    tutorial for github

    Hi, If i understand good,this script can be installed on github?

    If yes, can you please share the step by step procedure to install your script on my github account? And also how to link cloudlfare gateway with github for the blocklist.

    opened by madarie 14
  • clean up oisd li

    clean up oisd li

    Hello,

    Thank you for your work. I am trying to use your scripts with oisd list. Is there a good way to clean up the oisd big list? https://big.oisd.nl/

    It should be done in cf_list_create.js but not sure how.

    opened by norbertjoni 7
  • gateway locations

    gateway locations

    Hi, I need advice how to connect my mobile devices to cf gateway. Should we create new dns location for evry device to get the unique dot/doh adress ? Are there resctrictions on the zero trust free how many device/location we can have?

    opened by madarie 3
  • Oisd

    Oisd

    I am not sure if I am doing right, but I would like to pull this to the new branches named oisd. New branch because oisd list works well with all alone. This list prioritizes functionality over blocking.

    opened by norbertjoni 3
  • Fix the whitelist log and add ping health check

    Fix the whitelist log and add ping health check

    Whitelist log: Fixes an issue with the whitelist log generation, ensuring accurate records.

    Ping health check feature: Adds a ping health check using the provided PING_URL secret for proactive monitoring.

    opened by norbertjoni 2
  • whitelist

    whitelist

    Hi,

    the whitelist you added,is it automatically added when updating workflow? and can we select which whitelist we want to be used? I would prefer the hagezi's whitelist.

    opened by madarie 5
Owner
null
A web application that allows the user to connect through Unstoppable Domains and claim a small block of the site

FRAGMENTED Summary A web application that allows the user to connect through Unstoppable Domains and claim a small block of the site. Each user will b

null 2 Jan 24, 2022
🪐 The IPFS gateway for NFT.Storage is not "another gateway", but a caching layer for NFTs that sits on top of existing IPFS public gateways.

nftstorage.link The IPFS gateway for nft.storage is not "another gateway", but a caching layer for NFT’s that sits on top of existing IPFS public gate

NFT.Storage 37 Dec 19, 2022
Cloudflare DDNS (Dynamic DNS) support for UniFi OS

Cloudflare DDNS for UniFi OS A Cloudflare Worker script that exposes a UniFi-compatible DDNS API to dynamically update the IP address of a DNS A recor

William Walker 210 Jan 1, 2023
Please do not use this tracker to scam anyone! This is free and will be forever free. This tracking will never ask for seed phrases nor private keys. Keep safe!

CryptoBlades Tracker Related modules express - web application framework for node pug - template engine stylus - pre-processor CSS mongoose - nodejs o

null 355 Oct 13, 2022
A flexible gateway for running ML inference jobs through cloud providers or your own GPU. Powered by Replicate and Cloudflare Workers.

Cogflare (Working title) Cogflare is a Cloudflare Workers application that aims to simplify running distributed ML inference jobs through a central AP

NightmareBot 14 Dec 12, 2022
A block preview that directly displays the block fields, including tabs.

Kirby Block Preview Fields This plugin for Kirby 3 displays the block fields directly in the block preview, including tabs. Inspired by the Kirby Fiel

JUNO 8 May 10, 2023
This repo was made to bring to light all discord scams, and show how to tell if you are being scammed and how to remove malware from scams

DMV (Discord Malware Variants) is a repository made to bring light to harmful programs used by bad actors in order to steal sensitive information from

Credit 43 Dec 29, 2022
This repo was made to bring to light all discord scams, and show how to tell if you are being scammed and how to remove malware from scams

DMV (Discord Malware Variants) is a repository made to bring light to harmful programs used by bad actors in order to steal sensitive information from

opsec-bot 26 Sep 5, 2022
🖼️ Image proxy for Next.js. Makes it possible to use dynamic domains in next/image component.

Next.js Image Proxy Image proxy for Next.js. Makes it possible to use dynamic domains in next/image component. ❔ Motivation This library makes it poss

Blazity 30 Dec 1, 2022
This is 2D Black Hole Visualization

Blackhole Live demo Blackhole Calculations How to run in your machine? Clone or download ZIP file Then open HTML file in VS code and run with live ser

Nikhil Yadav 13 Jan 7, 2023
Synchronize multiple Pi-hole instances

Orbital Sync Orbital Sync synchronizes multiple Pi-hole instances for high availability (HA) using the built-in "teleporter". In other words, it perfo

Matt Webb 32 Dec 30, 2022
N8n node for using the Pi-hole API

n8n Pi-hole API client This is an N8n community node. It allows you to use the Pi-hole API [1],[2], in your workflow. Most of the resources provided b

Hugo Alves 3 Oct 8, 2022
Website to test solving the rabbit hole challenge.

?? Rabbit in the Hole Challenge This website is designed to show solutions and possibilities for the Rabbit in the Hole Challenge. ?? What is the chal

Nícolas Gabriel 5 Oct 18, 2022
Node.js package with a customized HTTP and HTTPS agents to prevent SSRF with hosts validations and custom DNS feature.

http-agent-dns This is a Node.js package with a customized HTTP and HTTPS agents to prevent SSRF with hosts validations with a possibility to use a cu

Bruno Germano 4 Jul 21, 2022
DNS-Blocklists: For a better internet - keep the internet clean!

DNS Blocklists - For a better internet! Multi - Cleans the Internet and protects your privacy! An all in one blocklist based on the OISD blocklist, ba

Gerd 280 Jan 2, 2023
A (multi) DNS-over-HTTPS resolver for Node.js

doh-resolver A DNS-over-HTTPS resolver for Node.js. Install $ npm install doh-resolver --save Usage It can be used as dns.resolve4 and/or dns.resolve6

Kiko Beats 6 Jul 20, 2022
🤖 An action that fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with them from time to time.

Discord Guardian Action ??  This action fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with t

Dalton Menezes 7 Nov 30, 2022
Borscht - A Russian service monitor to track the uptime of domains and services

borscht ?? Borscht is a simple uptime and status monitor of Russian sites and services You can view the public status page here ?? About ?? This proje

Grant Birkinbine 10 Jul 8, 2022
Input a list of Handshake top-level domains, outputs names sorted into 4 arrays: available, registered, reserved, or invalid.

name-check A simple NodeJS package that, given a flat list of top-level domain names, queries the Handshake (HNS) blockchain in order to classify each

Neel Yadav 2 Jan 8, 2022