项目作者: nickrobison

项目描述 :
Golang client for dynamically updating cloudflare DNS records
高级语言: Go
项目地址: git://github.com/nickrobison/go-cddns.git
创建时间: 2016-10-18T06:44:49Z
项目社区:https://github.com/nickrobison/go-cddns

开源协议:MIT License

下载


License: MIT
Build Status
Download

go-cddns

Golang client for dynamically updating cloudflare DNS records on a specified interval. Useful if you’re using Cloudflare to point to a device with a dynamic IP Address

Installation

Go package

  1. go get -u github.com/nickrobison/go-cddns

Debian repository

We also now have a debian (and Ubuntu) repository with builds for both amd64 and arm architectures.
Since we require systemd, the builds only support debian jessie and newer, and ubuntu xenial (16.04) and later.

The repository is hosted on bintray, so there are some special setup instructions.

  1. sudo apt-get install apt-transport-https # Bintray only supports https connections
  2. echo "deb https://dl.bintray.com/nickrobison/debian {xenial|jessie|stretch} main" | sudo tee -a /etc/apt/sources.list
  3. apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61 # We need to import the Bintray public key
  4. sudo apt-get update && apt-get install go-cddns

The package installation will create a config file in /etc/go-cddns/config.json, which is where you should set your configuration options.

Usage

Create a config.json with the following structure:

  1. {
  2. "UpdateInterval": "{interval (in minutes) to check for an updated IP Address}",
  3. "Key": "{Cloudflare API Key}",
  4. "Email": "{Cloudflare Email Address}",
  5. "DomainName": "{Cloudflare domain to modify}",
  6. "RecordName": "{Array of DNS records to update}",
  7. "Remove": "{Boolean of whether or not to remove the records on shutdown}"
  8. }

Run the application, optionally specifying the path to the config file.

  1. go-cddns -config=/path/to/file

Docker Image

go-cddns is also provided as a Docker image.
The application automatically starts when the container boots, but it lacks a functioning config file.
You’ll need to add the path to the desired config as a volume.

  1. docker run -v /{path/to/config}/config.json:/etc/config.json nickrobison/go-cddns

The container can be controlled by systemd via a custom unit file, such as this:

  1. [Unit]
  2. Description=Go-cddns container
  3. Requires=docker.service
  4. After=docker.service
  5. [Service]
  6. TimeoutStartSec=0
  7. Restart=always
  8. ExecStartPre=-/usr/bin/docker kill nickrobison/go-cddns
  9. ExecStartPre=-/usr/bin/docker rm nickrobison/go-cddns
  10. ExecStartPre=/usr/bin/docker pull nickrobison/go-cddns
  11. ExecStart=/usr/bin/docker run --rm -v /etc/go-cddns/config.json:/etc/config.json nickrobison/go-cddns
  12. ExecStop=/usr/bin/docker stop nickrobison/go-cddns
  13. [Install]
  14. WantedBy=local.target

Save this file as go-cddns.service within the systemd/system directory.
You can start immediately and at boot, by running: systemctl enable --now go-cddns.

Notes

  • The update interval must be more than 5 minutes, per the WhatIsMyIP API rules.
  • The records names must be FQDNs, even though they don’t appear in the cloudflare dashboard as such.
  • If the Remove field is set to true, the listed DNS records will be removed when the program exits.