simplyddns

package module
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Simply DDNS - Yet Another Universal DDNS Tools

SimplyDDNS is a universal DDNS tool that can be used to update domain name records based on obtained IP addresses. It is designed to be flexible and easy to extend. We also privide the Chinese version of this README file, see README_ZH.md.

This tool simply monitors and updates domain name records based on obtained IP addresses. While there are similar existing projects that are already very useful, there were several points that didn't meet my personal expectations and requirements:

  1. I don't need a UI interface; instead, I prefer a fully functional configuration file
  2. Need more flexibility and freedom in configuration combinations
  3. As a server-side application, more detailed logging and ability to transmit required information

Since this is actually a strong requirement (everyone knows that when setting up a website, the last step is changing DNS, which is very troublesome and error-prone), this application was created. While it may have a relatively higher configuration threshold, it offers more flexibility.

Concepts

Dynamic DNS registration (DDNS) behavior is abstracted into two types: how to obtain IP addresses and how to configure DNS.

Therefore, by implementing these two interfaces and matching them with configurations, you can flexibly arrange and run them. See the Extensions section for details.

Installation

For security considerations, binary executables are not provided at this time. If you need to compile the binary yourself, you can refer to the configuration in the Makefile.

Usually, make build is a very good choice. After running it (of course, requiring the Golang development environment), you can generate the corresponding executable file in the current directory.

docker-compose

It's recommended to run this application using containers. The program provides compose.yml and Dockerfile files for easy image building and running.

Configuration

Detailed configuration file examples are in the example directory. Here's a very simple example (from basic.yml):

logfile: "/dev/stderr"
debug: True

ddns:
  - source:
      type: "lo"
      interval: 60 # 1 minute
    target:
      type: "sleep"

This configuration file means getting the IP address from the lo module and passing it to the sleep target for execution. The sleep target does nothing except sleep for a few seconds, but this demonstrates SimplyDDNS's working mechanism.

Extensions

Extending SimplyDDNS is very easy. You can refer to the corresponding files in the source and target directories. The simplest ones are lo.go and sleep.go in the target directory, as they don't do anything practical.

source

lo

This module only returns the Lookup address, used for testing

static

Specifies the corresponding static address, usually used for fixed IP addresses

myip

Gets the IP address by accessing ipip.net, one of the recommended methods for obtaining IP addresses, used when the host has a public network address and can be accessed directly (such as DMZ hosts)

biturl

Another IP address acquisition service through accessing web addresses. The original ipsb service has been deprecated

target

sleep

Does nothing but sleep for a few seconds, can be used for testing

alidns

Uses Aliyun DNS service interface, requires backend API Key and Token application. Detailed usage is in target/alidns_test.go, and configuration example is in example/alidns.yml

namedotcom

Uses Name.com as the domain service backend. Because Name.com has whitelist verification, you can consider using a proxy if not accessing locally (see target/namedotcom_test.go)

cloudflare

Uses Cloudflare's API and SDK to provide dynamic updates for DNS deployed to Cloudflare. See related resources at https://developers.cloudflare.com/api/operations/dns-records-for-a-zone-list-dns-records and https://github.com/cloudflare/cloudflare-go

FAQ

If I only have one way to request IP addresses but multiple domains, repeating configurations makes it look bloated. Is there a better solution?

This is a common scenario. You can consider using Yaml's reference feature to reduce repeated configurations, for example:

defaults: &defaults
  type: lo
  interval: 60

First define returning a local address from lo every minute, then configure the corresponding domain updates:

ddns:
  - source:
      <<: *defaults
    target:
      type: "sleep"
      domains:
        - a.com
        - b.com
  - source:
      <<: *defaults
    target:
      type: "another"
      domains:
        - c.com
        - d.com

After configuring this way, you only need to focus on the target (domain) configuration.

WebHook Configuration

WebHook can notify users of any configuration changes. You can use the following configuration:

webhook:
  url: https://<your-webhook-address>

After configuring like this, when the address changes, the results and changed domain results will be POSTed to the corresponding address. The result format is as follows:

{
    "address": "127.0.0.1",
    "domains": "a.com,b.com",
    "now": "2022-07-13T15:00:10.931809+08:00"
}

If there are multiple domain results, they will be separated by commas.

- eof -

Documentation

Index

Constants

View Source
const (
	// DefaultInterval is the default check interval in seconds
	DefaultInterval = 60

	// MinInterval is the minimum allowed check interval in seconds
	MinInterval = 30

	// MaxRetries is the maximum number of retries for failed requests
	MaxRetries = 3

	// DefaultTimeout is the default timeout for HTTP requests
	DefaultTimeout = 30 * time.Second

	// DefaultUserAgent is the default user agent for HTTP requests
	DefaultUserAgent = "SimpleDDNS/1.0"
)

Variables

This section is empty.

Functions

func GetAllSupportSourceFunc

func GetAllSupportSourceFunc() []string

GetAllSupportSourceFunc returns the names of every registered source function.

func NewLogger

func NewLogger() *logrus.Logger

NewLogger returns the shared logger instance, initialising it on first use.

func ParseDomain

func ParseDomain(domain string) (*tld.URL, error)

ParseDomain parses a bare domain name into its components using go-tld. See https://github.com/jpillora/go-tld for details.

func ProxyHttpClient

func ProxyHttpClient(addr string) (*http.Client, error)

ProxyHttpClient creates an http.Client backed by a SOCKS5 proxy at addr.

func RegisterSourceFunc

func RegisterSourceFunc(name string, fn SourceFunc) error

RegisterSourceFunc registers a new source function under the given name. It returns an error if a function with the same name is already registered.

func RegisterTargetFunc

func RegisterTargetFunc(name string, fn TargetFunc) error

RegisterTargetFunc registers a new target function under the given name. It returns an error if a function with the same name is already registered.

func ValidateConfig

func ValidateConfig(config *JobConfig) error

ValidateConfig performs basic sanity checks on a JobConfig.

func ValidateRecord

func ValidateRecord(domain string, addr *net.IP) error

ValidateRecord checks whether the given domain currently resolves to addr.

func ValidateRecords

func ValidateRecords(domains []string, addr *net.IP) error

ValidateRecords validates each domain in the list against the given address. It returns nil only when every domain already resolves to addr.

Types

type Auth

type Auth struct {
	User     string `yaml:"username" mapstructure:"username"`
	Password string `yaml:"password" mapstructure:"password"`
}

type Config

type Config struct {
	LogFile  string      `yaml:"logfile" mapstructure:"logfile"`
	Debug    bool        `yaml:"debug" mapstructure:"debug"`
	LoadUI   bool        `yaml:"ui" mapstructure:"ui"`
	BindAddr string      `yaml:"addr" mapstructure:"addr"`
	Auth     Auth        `yaml:"auth" mapstructure:"auth"`
	Jobs     []JobConfig `yaml:"ddns" mapstructure:"ddns"`
}

type Dispatch

type Dispatch struct {
	Timeout time.Duration
	Configs []JobConfig
	// contains filtered or unexported fields
}

Dispatch coordinates a set of DDNS jobs that run concurrently.

func NewDispatch

func NewDispatch(configs []JobConfig) (*Dispatch, error)

NewDispatch creates a new Dispatch from the given job configurations.

func (*Dispatch) Start

func (d *Dispatch) Start(ctx context.Context)

Start runs every job concurrently and blocks until all of them return.

func (*Dispatch) Stop

func (d *Dispatch) Stop()

Stop signals every job to stop and waits for them to return.

type Job

type Job struct {
	Config     *JobConfig
	SourceFunc []SourceFunc
	TargetFunc TargetFunc
	// contains filtered or unexported fields
}

Job represents a running DDNS job created from a JobConfig.

func NewJob

func NewJob(config JobConfig) (*Job, error)

NewJob creates a new Job from the given JobConfig.

func (*Job) RunWebhook

func (j *Job) RunWebhook(ctx context.Context, addr string, domains []string) error

RunWebhook triggers the configured webhook after a successful address update.

func (*Job) Source

func (j *Job) Source(ctx context.Context, config *SourceConfig) (*net.IP, error)

Source executes every registered source function for this job and returns the resolved address. When multiple source functions are configured, they must all agree on the same address; otherwise an error is returned.

func (*Job) Start

func (j *Job) Start(ctx context.Context)

Start runs the job loop until Stop is called or the context is done. Each tick fetches the address from the source, optionally validates it against the configured domains and applies the target function.

func (*Job) Stop

func (j *Job) Stop()

Stop signals the job loop to exit.

type JobConfig

type JobConfig struct {
	WebHook WebHook      `yaml:"webhook" mapstructure:"webhook"`
	Source  SourceConfig `yaml:"source,omitempty" mapstructure:"source"`
	Target  TargetConfig `yaml:"target,omitempty" mapstructure:"target"`
}

JobConfig describes a single DDNS job, composed of a source, a target and an optional webhook.

type SourceConfig

type SourceConfig struct {
	Interval uint   `yaml:"interval,omitempty"`
	Type     string `yaml:"type,omitempty"`
	Path     string `yaml:"path"`
	Content  string `yaml:"content"`
}

SourceConfig describes how a source function obtains the public IP address.

type SourceFunc

type SourceFunc func(context.Context, *SourceConfig) (*net.IP, error)

SourceFunc resolves the current IP address from a configured source.

func SourceFuncByName

func SourceFuncByName(name string) (SourceFunc, error)

SourceFuncByName looks up a registered source function by name.

type TargetConfig

type TargetConfig struct {
	Type    string   `yaml:"type,omitempty"`
	Key     string   `yaml:"key,omitempty"`
	Token   string   `yaml:"token"`
	Proxy   string   `yaml:"proxy"`
	Domains []string `yaml:"domains,omitempty"`
}

TargetConfig describes how a target function updates DNS records.

type TargetFunc

type TargetFunc func(context.Context, *net.IP, *TargetConfig) error

TargetFunc applies the given IP address to a configured target.

func TargetFuncByName

func TargetFuncByName(name string) (TargetFunc, error)

TargetFuncByName looks up a registered target function by name.

type WebHook

type WebHook struct {
	Url      string `yaml:"url" mapstructure:"url"`
	Token    string `yaml:"token" mapstructure:"token"`
	UserName string `yaml:"username" mapstructure:"username"`
	Password string `yaml:"password" mapstructure:"password"`
}

WebHook describes the webhook triggered when the address changes.

Directories

Path Synopsis
cmd
simplyddns command
simplyddns is a simple dynamic DNS client
simplyddns is a simple dynamic DNS client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址