GithubHelp home page GithubHelp logo

acidiclight / cloudflare-ddns-daemon Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 12 KB

Simple Node.js service that implements dynamic DNS using the Cloudflare API, allowing for hosting home websites with less headaches.

License: MIT License

JavaScript 100.00%

cloudflare-ddns-daemon's Introduction

Cloudflare Dynamic DNS Daemon

This is an extremely simple daemon written in Node.js that implements Dynamic DNS using the Cloudflare API.

What is this for?

Some of us, including myself, have a home server that needs to be accessible through the Internet. This server may host a personal website, a game server, or any number of other things.

Unfortunately, a limitation with IPv4 is that IPv4 addresses are 32 bits long, and there are not enough addresses to give every household on the planet a static public IP address. Although IPv6 was designed to rectify this, some users still cannot use IPv6.

Because of this, most ISPs will give household customers a dynamic IP address, which changes periodically or every time the modem/router is rebooted. It may be possible to get a static IP address, but some ISPs may charge an extra fee or limit it only to small businesses.

This causes a problem if you try to point a domain name to your home network. It will work fine for the first little while, but your IP address will change and the website/gameserver/whatnot will go down as a result. This is what Dynamic DNS is designed to solve.

How does this program work?

This program works by running as a system service on your home server. It will periodically check the network configuration to figure out what your current dynamic public IP address is. It will also check what IP address your domain name is pointing at, and if they're different, it will use the Cloudflare API to update the relevant DNS record.

Setting this up

You will need Git and the latest version of Nodejs installed on the system you want to run this daemon on.

Step 0: Get your domain name on Cloudflare.

Because this program uses the Cloudflare API, you will need to have a Cloudflare account and add your domain name to it. You can use the free plan.

Follow Cloudflare's instructions to add the domain name to your account, and wait for it to become active. Once it's active, and you've created an A record for your domain name, we're good to go.

You'll also need an API token with the ability to edit Zone DNS records. See the Getting Started section of the Cloudflare API docs for information.

Step 1: Get the code.

Start by cloning the repository. These instructions assume a Linux system with systemd as the init system, feel free to adapt it to your needs.

Run the following commands to clone the repository, install npm dependencies, and move the application to /opt/cloudflare-ddns.

# clone the repository into somewhere you have access to
cd ~
git clone https://github.com/alkalinethunder/cloudflare-ddns-daemon

# Install node dependencies
cd cloudflare-ddns-daemon/src
npm install

## Copy the source code over to /opt/cloudflare-ddns
cd ..
sudp cp -R src /opt/cloudflare-ddns

Step 2: Create a systemd daemon.

From here, you can create a launcher script that sets the necessary environment variables before running the daemon.

/bin/cloudflare-ddns:

#!/bin/bash
export CLOUDFLARE_API_TOKEN=<Replace this with your API token>
export CLOUDFLARE_ZONE=aklnthndr.dev # Replace this with your root domain name.
# If you are updating a subdomain, uncomment this and put the DNS record name here.
#export DNS_RECORD_NAME=sparky
node /opt/cloudflare-ddns/index.js

Make sure it's executable.

sudo chmod +x /bin/cloudflare-ddns

Now we can create a unit file, in /etc/systemd/system/cloudflare-ddns.service:

[Unit]
Description=Cloudflare Dynamic DNS Daemon
After=network.target auditd.service

[Service]
ExecStart=/bin/cloudflare-ddns
Restart=on-failure

[Install]
WantedBy=multi-user.target

Congrats! You now know how to suffer pain. But don't worry. The pain's over.

Step 3: Enable and start the service.

sudo systemctl enable cloudflare-ddns
sudo systemctl start cloudflare-ddns

All done.

cloudflare-ddns-daemon's People

Contributors

acidiclight avatar

Watchers

James Cloos avatar  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.