Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cycneuramus/cloudflare-dns-failover
A simple Go program implementing automatic DNS failover via Cloudflare's API.
https://github.com/cycneuramus/cloudflare-dns-failover
cloudflare ddns dns-failover dynamic-dns go golang healthchecks selfhosted
Last synced: about 6 hours ago
JSON representation
A simple Go program implementing automatic DNS failover via Cloudflare's API.
- Host: GitHub
- URL: https://github.com/cycneuramus/cloudflare-dns-failover
- Owner: cycneuramus
- License: gpl-3.0
- Created: 2024-02-11T15:43:13.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-05-28T06:57:43.000Z (7 months ago)
- Last Synced: 2024-11-09T03:42:28.255Z (about 2 months ago)
- Topics: cloudflare, ddns, dns-failover, dynamic-dns, go, golang, healthchecks, selfhosted
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloudflare DNS Failover
A small Go program that provides a simple yet effective solution for automatic DNS failover using [Cloudflare's](https://www.cloudflare.com/application-services/products/dns) API.
The program monitors a list of server IPs in order of priority and updates the A record for a specified domain to the IP address of the first responsive server. This ensures high availability and reliability of services by automatically switching to a backup server in case the primary server goes down.
This DNS failover mechanism is not to be confused with [round-robin DNS](https://en.wikipedia.org/wiki/Round-robin_DNS), where multiple A records are set for the same domain to distribute traffic randomly across different servers. While potentially useful, this cannot be depended upon for site reliability, since if one of the servers goes down, the DNS server will still keep that server’s IP in the round-robin rotation.
## Prerequisites
Before you begin, ensure you have met the following requirements:
- A Cloudflare account with access to API tokens.
## Installation
1. **Clone the repository:**
```bash
git clone https://github.com/cycneuramus/cloudflare-dns-failover
cd cloudflare-dns-failover
```2. **Configure your records**
Open the `config.yml.example` with your preferred text editor and edit the placeholder values. Save the file as `config.yml`.
3. **Build the program**
```bash
go build .
```## Usage
To start the DNS failover mechanism, simply run the program:
```bash
./cloudflare-dns-failover
```This assumes that `config.yml` exists in the working directory. You can, however, pass its path as a flag:
```bash
./cloudflare-dns-failover -c /path/to/config.yml
```The program executes in an infinite loop, checking the availability of the servers at the specified interval and updating the DNS record as needed.
To maintain continuous operation, ensure that the program is running in a stable environment (e.g. as a `systemd` service or perhaps even as an orchestrated `exec` job in a [Nomad](https://www.nomadproject.io/) cluster).