Giter Site home page Giter Site logo

cloudflare-ddns's Introduction

Cloudflare-DDNS

Simple Cloudflare dynamic DNS updater.

This program will update a Cloudflare DNS record dynamically to match your public IP.

Usage

Download and run as a standalone node application ($ node index) or with a process manager, such as pm2.

Make sure to have configuration set up in a config.json file.

This application will create a ddns.cache file upon startup, keep it as is.

If you need to update multiple entries, consider using CNAME DNS records on Cloudflare to have other records match the IP of the record you update using this script. However, this script now supports multiple record updates โ€” simply add another config object in the "configs" array below.

Example Configuration

{
    "configs": [
        {
            "email": "[email protected]",
            "key": "nQSSID7h7Ads2fyOeArShTmWhhj2D3c5kdtVomGFu0TIo",
            "zone": "ajs3j819jmxv48mdfp39rsfj38jssf135",
            "name": "example.com",
            "ipv6": false,
            "proxied": true
        }
    ],
    "refresh": 300
}

email: (String) The email associated with your cloudflare account.
key: (String) Your account's API key
zone: (String) The zone ID for your website. Found on the right side of the website overview on Cloudflare.
name: (String) The name of the record you are updating

Optional
ipv6: (Boolean) Whether or not your IP is an IPv6 IP address, true meaning it is. Default: false
proxied: (Boolean) Whether or not to proxy this record's traffic through Cloudflare's network. Default is none, meaning no change.
refresh: (int) How often to check for an IP change, in seconds. Default 300 seconds (5 minutes)

Note how all configuration settings are per-configuration, aside from refresh, which is global.

Example with two records:

{
    "configs": [
        {
            "email": "[email protected]",
            "key": "nQSSID7h7Ads2fyOeArShTmWhhj2D3c5kdtVomGFu0TIo",
            "zone": "ajs3j819jmxv48mdfp39rsfj38jssf135",
            "name": "example.com",
            "proxied": true
        },
        {
            "email": "[email protected]",
            "key": "nQSSID7h7Ads2fyOeArShTmWhhj2D3c5kdtVomGFu0TIo",
            "zone": "ajs3j819jmxv48mdfp39rsfj38jssf135",
            "name": "name.com",
            "ipv6": true
        }
    ],
    "refresh": 300
}

Full Setup

This will set up the application to run 24/7 using PM2, so that you can start it and forget it. (Will work on any OS that supports node.)

  1. Download and install node.js (LTS will do).
  2. Clone or download this repository, and open that folder.
  3. Create a config.json file that follows the example format above.
  4. Open a console in the current directory, and type npm install.
  5. To install PM2, type npm install -g pm2.
  6. Restart your command prompt.
  7. Test that the program works by running it with node index. If there are no errors and it has an "Init complete." message, you're good. Use Ctrl + C to terminate the program.
  8. Type pm2 start index.js --name="cddns" (you can replace "cddns" with another name if you'd like) to start the process with pm2.
  9. Type pm2 startup and follow the instructions to start the program (and any other programs running with pm2) on startup.
  10. Close your console and enjoy!

Update notes

Note, as of July 12th, 2023, this script supports multiple record updates. This comes with a non-backwards-compatible restructuring of ddns.cache and config.json. Please see above for how to set up the new config.json (the format is similar, but not the same). Please delete your old ddns.cache before running the newly-updated version. (This note is for the incredibly rare chance someone uses my script.. who would that be? I have no idea.)

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.