Sign inSign up

mmianl/ddns

By mmianl

Updated almost 3 years ago

Image
0

718

mmianl/ddns repository overview

DDNS

DDNS is a golang tool used to update dynamic DNS entries on supported dynamic DNS services.

Find the source code on Github.

Command line flags

The DDNS CLI lets you interact with the DDNS service

Usage:
  ddns [flags]
  ddns [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  run         Run A record synchronization once
  serve       Serve daemon that periodically performs A record synchronization

Flags:
      --config string     relative or absolute path to the config file (default "./config.yml")
  -h, --help              help for ddns
      --loglevel string   log level, possible values: trace, debug, info, warn, error, fatal, panic (default "info")
  -v, --version           version for ddns

Use "ddns [command] --help" for more information about a command.

Example Config File

waitInterval: "1m"
retryInterval: "10s"

metricsServer:
  enable: true
  host: 127.0.0.1
  port: 8080

staticIPAddressProvider:
  enable: false
  address: "10.0.0.1"

urlIPAddressProvider:
  enable: true
  url: "www.example.com/ipaddress"
  https: true
  insecureSkipVerify: false
  regex: ""
  username: "username"
  password: "password"

cloudflareDNSProvider:
  enable: true
  apiToken: "12345"
  zoneID: "12345"
  aRecords:
    - "example.com"
    - "www.example.com"

If multiple DNS or IP Address providers are specified in the config file, only one will take effect, The order of precedence is the order in which the providers are listed below, with the first provider having the highest priority.

Configuration parameters specified via environment variables take precedence over those specified in the config file.

Global Configuration Parameters

KeyEnv VarTypeDefault ValueRequiredDescription
waitIntervalDDNS_WAIT_INTERVALtime.Duration1mfalsetime.Duration to wait after successfully updating records
retryIntervalDDNS_RETRY_INTERVALtime.Duration5sfalsetime.Duration to wait after a failed attempt to update records

Metrics Server Configuration Parameters

Configuration Key: metricsServer

KeyEnv VarTypeDefault ValueRequiredDescription
enableDDNS_METRICS_ENABLEbooltruetrueEnable metrics endpoint listening on /metrics path
hostDDNS_METRICS_HOSTstring0.0.0.0falseHost to be bound by the metrics handler
portDDNS_METRICS_PORTstring9097falsePort to be bound by the metrics handler
Available Metrics
NameTypeHelp
ddns_build_infoGaugeMetric with a constant '1' value labeled by version and goversion from which ddns was built.
ddns_start_time_secondsGaugeStart time of the process since unix epoch in seconds.
ddns_dns_a_record_infoGaugeMetric with a constant '1' value showing the current a records and their ip addresses.

Available Providers for Retrieving the IP Address

StaticIPAddressProvider

Ip address provider that returns the static ip address that is provided in the config file.

Configuration Key: staticIPAddressProvider

KeyEnv VarTypeDefault ValueRequiredDescription
enableDDNS_STATIC_PROVIDER_ENABLEboolfalsetrueEnable this provider
addressDDNS_STATIC_PROVIDER_ADDRESSstring127.0.0.1falseStatic ip address to return
URLIPAddressProvider

Ip address provider that makes a get request against the url that is provided in the config file and parses the response body using the regex if defined.

Configuration Key: urlIPAddressProvider

KeyEnv VarTypeDefault ValueRequiredDescription
enableDDNS_URL_PROVIDER_ENABLEboolfalsetrueEnable this provider
urlDDNS_URL_PROVIDER_URLstring127.0.0.1falseURL to get the ip address from with a GET request
httpsDDNS_URL_PROVIDER_HTTPSbooltruefalseUse https when accessing the url if true, http otherwise
insecureSkipVerifyDDNS_URL_PROVIDER_INSECUREboolfalsefalseIgnore bad certificates when accessing the url
regexDDNS_URL_PROVIDER_REGEXstringfalseRegex to match the ip address containing a single numbered match group, see https://pkg.go.dev/regexp/syntax
usernameDDNS_URL_PROVIDER_USERNAMEstringfalseBasic auth username to use when accessing the url, only set if required
passwordDDNS_URL_PROVIDER_PASSWORDstringfalseBasic auth password to use when accessing the url, only set if required

For example, if the website https://www.example.com/ipaddress returned this json:

{"address":"192.168.0.100"}

Then the following configuration could be used to get the ip address from there:

urlIPAddressProvider:
  enable: true
  url: "www.example.com/ipaddress"
  regex: '"address":\s?"(.*)"'

Available DNS Providers

CloudflareDNSProvider

Configuration Key: cloudflareDNSProvider

KeyEnv VarTypeDefault ValueRequiredDescription
enableDDNS_CLOUDFLARE_PROVIDER_ENABLEboolfalsetrueEnable this provider
apiTokenDDNS_CLOUDFLARE_API_TOKENstringtrueCloudflare API token with All zones - DNS:Read, DNS:Edit permissions
zoneIDDDNS_CLOUDFLARE_PROVIDER_ZONE_IDstringtrueCloudflare zone id
aRecordsDDNS_CLOUDFLARE_PROVIDER_RECORDS[]stringtrueList of A records to update

Build Docker Image

export VERSION=`cat VERSION`
docker build . -t ddns:v${VERSION}

Example Systemd Service File

This service file assumes that a user called ddns exists, and that the config file is located at /etc/ddns/ddns.yaml.

sudo groupadd ddns
sudo useradd -r -g ddns ddns
sudo mkdir /etc/ddns
# Write config file to /etc/ddns/ddns.yaml
sudo chmod 600 /etc/ddns/ddns.yaml
sudo chown ddns:ddns -R /etc/ddns/
[Unit]
Description=Dynamic DNS Client
After=network.target

[Service]
Type=simple
User=ddns
ExecStart=/usr/local/bin/ddns -config /etc/ddns/ddns.yaml

[Install]
WantedBy=multi-user.target

Tag summary

Content type

Image

Digest

sha256:2361fe74d

Size

8.7 MB

Last updated

almost 3 years ago

docker pull mmianl/ddns:v0.0.8