godns

package module
v0.0.0-...-7c36ba8 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

README

 ██████╗  ██████╗ ██████╗ ███╗   ██╗███████╗
██╔════╝ ██╔═══██╗██╔══██╗████╗  ██║██╔════╝
██║  ███╗██║   ██║██║  ██║██╔██╗ ██║███████╗
██║   ██║██║   ██║██║  ██║██║╚██╗██║╚════██║
╚██████╔╝╚██████╔╝██████╔╝██║ ╚████║███████║
 ╚═════╝  ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝

Apache licensed Docker Go Report Card Cover.Run GoDoc

GoDNS is a dynamic DNS (DDNS) client tool, it is based on my early open source project: DynDNS.

Now I rewrite DynDNS by Golang and call it GoDNS.

Supported DNS Providers

Supported Platforms

  • Linux
  • MacOS
  • ARM Linux (Raspberry Pi, etc...)
  • Windows
  • MIPS32 platform

MIPS32 platform

To compile binaries for MIPS (mips or mipsle):

GOOS=linux GOARCH=mips/mipsle GOMIPS=softfloat go build -a

And the binary can run well on routers.

Pre-condition

Get it

Build it from source code

  • Get source code from Github:
git clone https://github.com/jmbayu/godns.git
  • Go into the godns directory, get related library and then build it:
cd cmd/godns
go get -v
go build

Download from releases

Download compiled binaries from releases

Get help

$ ./godns -h
Usage of ./godns:
  -c string
        Specify a config file (default "./config.json")
  -h    Show help

Config it

  • Get config_sample.json from Github.
  • Rename it to config.json.
  • Configure your provider, domain/subdomain info, username and password, etc.
  • Configure the SMTP options if you want, a mail notification will sent to your mailbox once the IP is changed.
  • Save it in the same directory of GoDNS, or use -c=your_conf_path command.

Config fields

  • provider: The providers that GoDNS supports, available values are: Cloudflare, Google, DNSPod, AliDNS, HE, DuckDNS, Dreamhost.
  • email: Email or account name of your DNS provider.
  • password: Password of your account.
  • login_token: API token of your account.
  • domains: Domains list, with your sub domains.
  • ip_url: A site helps you to get your public IPv4 IP address.
  • ipv6_url: A site helps you to get your public IPv6 address.
  • ip_type: To configure GoDNS under IPv4 mode or IPv6 mode, available values are: IPv4, IPv6.
  • interval: The interval seconds that GoDNS check your public IP.
  • socks5_proxy: Socks5 proxy server.
  • resolver: The address of the public DNS server. For example, to run GoDNS in IPv4 mode, you can set resolver as 8.8.8.8, to GoDNS in IPv6 mode, you can set resolver as 2001:4860:4860::8888.

IPv6 support

Supported provider(s):

  • Cloudflare
  • DNSPod
  • Dreamhost
  • DuckDNS
  • Google Domains
  • HE.net
  • No-IP

To enable the IPv6 support of GoDNS, there are 2 solutions you can choose:

  • Get IPv6 address online
  • Get IPv6 address from your network interface

To get IPv6 address online:

  • Set the ip_type as IPv6, and make sure the ipv6_url is configured.
  • Add one AAAA record to your provider.

For example:

{
  "domains": [
    {
      "domain_name": "example.com",
      "sub_domains": [
        "ipv6"
      ]
    }
  ],
  "resolver": "2001:4860:4860::8888",
  "ipv6_url": "https://api-ipv6.ip.sb/ip",
  "ip_type": "IPv6"
}

To get IPv6 address from your interface:

It is quite simple, just left "ip_url" & "ipv6_url" as empty. Please note that an IPv6 address configured for your interface is the prerequisite for this feature.

Config example for Cloudflare

For Cloudflare, you need to provide the email & Global API Key as password (or to use the API token) and config all the domains & subdomains.

  • Using email & Global API Key
{
  "provider": "Cloudflare",
  "email": "you@example.com",
  "password": "Global API Key",
  "domains": [{
      "domain_name": "example.com",
      "sub_domains": ["www","test"]
    },{
      "domain_name": "example2.com",
      "sub_domains": ["www","test"]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "interval": 300,
  "socks5_proxy": ""
}
  • Using the API Token
{
  "provider": "Cloudflare",
  "login_token": "API Token",
  "domains": [{
      "domain_name": "example.com",
      "sub_domains": ["www","test"]
    },{
      "domain_name": "example2.com",
      "sub_domains": ["www","test"]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "interval": 300,
  "socks5_proxy": ""
}

Config example for DNSPod

For DNSPod, you need to provide your API Token(you can create it here), and config all the domains & subdomains.

{
  "provider": "DNSPod",
  "login_token": "your_id,your_token",
  "domains": [{
      "domain_name": "example.com",
      "sub_domains": ["www","test"]
    },{
      "domain_name": "example2.com",
      "sub_domains": ["www","test"]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "ip_type": "IPV4",
  "interval": 300,
  "socks5_proxy": ""
}

Config example for Dreamhost

For Dreamhost, you need to provide your API Token(you can create it here), and config all the domains & subdomains.

{
  "provider": "Dreamhost",
  "login_token": "your_api_key",
  "domains": [{
      "domain_name": "example.com",
      "sub_domains": ["www","test"]
    },{
      "domain_name": "example2.com",
      "sub_domains": ["www","test"]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "ip_type": "IPV4",
  "interval": 300,
  "resolver": "ns1.dreamhost.com",
  "socks5_proxy": ""
}

Config example for Google Domains

For Google Domains, you need to provide email & password, and config all the domains & subdomains.

{
  "provider": "Google",
  "email": "Your_Username",
  "password": "Your_Password",
  "domains": [{
      "domain_name": "example.com",
      "sub_domains": ["www","test"]
    },{
      "domain_name": "example2.com",
      "sub_domains": ["www","test"]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "interval": 300,
  "socks5_proxy": ""
}

Config example for AliDNS

For AliDNS, you need to provide AccessKeyID & AccessKeySecret as email & password, and config all the domains & subdomains.

{
  "provider": "AliDNS",
  "email": "AccessKeyID",
  "password": "AccessKeySecret",
  "login_token": "",
  "domains": [{
      "domain_name": "example.com",
      "sub_domains": ["www","test"]
    },{
      "domain_name": "example2.com",
      "sub_domains": ["www","test"]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "interval": 300,
  "socks5_proxy": ""
}

Config example for DuckDNS

For DuckDNS, only need to provide the token, config 1 default domain & subdomains.

{
  "provider": "DuckDNS",
  "password": "",
  "login_token": "3aaaaaaaa-f411-4198-a5dc-8381cac61b87",
  "domains": [
    {
      "domain_name": "www.duckdns.org",
      "sub_domains": [
        "myname"
      ]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "interval": 300,
  "socks5_proxy": ""
}

Config example for No-IP

{
  "provider": "NoIP",
  "email": "mail@example.com", 
  "password": "YourPassword",
  "domains": [
    {
      "domain_name": "ddns.net",
      "sub_domains": ["timothyye6"]
    }
  ],
  "ip_type": "IPv4",
  "ip_url": "https://myip.biturl.top",
  "resolver": "8.8.8.8",
  "interval": 300,
  "socks5_proxy": ""
}

Config example for HE.net

For HE, email is not needed, just fill DDNS key to password, and config all the domains & subdomains.

{
  "provider": "HE",
  "password": "YourPassword",
  "login_token": "",
  "domains": [{
      "domain_name": "example.com",
      "sub_domains": ["www","test"]
    },{
      "domain_name": "example2.com",
      "sub_domains": ["www","test"]
    }
  ],
  "resolver": "8.8.8.8",
  "ip_url": "https://myip.biturl.top",
  "interval": 300,
  "socks5_proxy": ""
}

HE.net DDNS configuration

Add a new "A record", make sure that "Enable entry for dynamic dns" is checked:

Fill your own DDNS key or generate a random DDNS key for this new created "A record":

Remember the DDNS key and fill it as password to the config.json.

NOTICE: If you have multiple domains or subdomains, make sure their DDNS key are the same.

Get an IP address from the interface

For some reasons if you want to get an IP directly from the interface, say eth0 for Linux or Local Area Connection for Windows, update config file like this:

  "ip_url": "",
  "ip_interface": "eth0",

If you set both ip_url and ip_interface, it first tries to get an IP address online, and if not succeed, gets an IP address from the interface as a fallback.

Email notification support

Update config file and provide your SMTP options, a notification mail will be sent to your mailbox once the IP is changed and updated.

  "notify": {
    "mail": {
      "enabled": true,
      "smtp_server": "smtp.example.com",
      "smtp_username": "user",
      "smtp_password": "password",
      "smtp_port": 25,
      "send_to": "my_mail@example.com"
    }
  }

Notification mail example:

Telegram notification support

Update config file and provide your Telegram options, a notification message will be sent to your telegram channel once the IP is changed and updated.

  "notify": {
    "telegram": {
      "enabled": true,
      "bot_api_key": "11111:aaaa-bbbb",
      "chat_id": "-123456",
      "message_template": "Domain *{{ .Domain }}* is updated to %0A{{ .CurrentIP }}",
      "use_proxy": false
    },
  }

Markdown is supported in message template, and use %0A for newline.

Slack notification support

Update config file and provide your Slack options, a notification message will be sent to your slack channel once the IP is changed and updated.

  "notify": {
    "slack": {
      "enabled": true,
      "bot_api_token": "xoxb-xxx",
      "channel": "your_channel",
      "message_template": "Domain *{{ .Domain }}* is updated to \n{{ .CurrentIP }}",
      "use_proxy": false
    },
  }

Markdown is supported in message template, and use \n for newline.

SOCKS5 proxy support

You can also use SOCKS5 proxy, just fill SOCKS5 address to the socks5_proxy item:

"socks5_proxy": "127.0.0.1:7070"
"use_proxy": true

Now all the queries will go through the specified SOCKS5 proxy.

Run it as a daemon manually

nohup ./godns &

Run it as a daemon, manage it via Upstart

  • Install upstart first
  • Copy ./upstart/godns.conf to /etc/init
  • Start it as a system service:
sudo start godns

Run it as a daemon, manage it via Systemd

  • Modify ./systemd/godns.service and config it.
  • Copy ./systemd/godns.service to /lib/systemd/system
  • Start it as a systemd service:
sudo systemctl enable godns
sudo systemctl start godns

Run it with docker

Now godns supports to run in docker.

docker run -d --name godns --restart=always \
-v /path/to/config.json:/usr/local/godns/config.json timothyye/godns:latest

Run it as a Windows service

After creating your config.json file:

  • Get the latest NSSM for create a windows service.
  • Open the command prompt (as administrator) in the folder where you downloaded NSSM (e.g. C:\Downloads\nssm\ win64) and run:
nssm install YOURSERVICENAME

You will have an interface to configure your service, it is very simple in the "Application" tab just indicate where your godns.exe file is. Optionally you can also define a description on the "Details" tab and define a log file on the "I/O" tab.

  • Finish using the "Install service" button.
  • Done. Now whenever windows start your service will be loaded.
  • To uninstall:
nssm remove YOURSERVICENAME

Special Thanks

Thanks JetBrains for sponsoring this project with free open source license.

I like GoLand, it is an amazing and productive tool.

Documentation

Index

Constants

View Source
const (
	// PanicMax is the max allowed panic times
	PanicMax = 5
	// DNSPOD for dnspod.cn
	DNSPOD = "DNSPod"
	// HE for he.net
	HE = "HE"
	// CLOUDFLARE for cloudflare.com
	CLOUDFLARE = "Cloudflare"
	// ALIDNS for AliDNS
	ALIDNS = "AliDNS"
	// GOOGLE for Google Domains
	GOOGLE = "Google"
	// DUCK for Duck DNS
	DUCK = "DuckDNS"
	// DREAMHOST for Dreamhost
	DREAMHOST = "Dreamhost"
	// NOIP for NoIP
	NOIP = "NoIP"
	// IPV4 for IPV4 mode
	IPV4 = "IPV4"
	// IPV6 for IPV6 mode
	IPV6 = "IPV6"
)

Variables

View Source
var (
	Logo = `` /* 774-byte string literal not displayed */

)

Functions

func CheckSettings

func CheckSettings(config *Settings) error

CheckSettings check the format of settings

func GetCurrentIP

func GetCurrentIP(configuration *Settings) (string, error)

GetCurrentIP gets an IP from either internet or specific interface, depending on configuration

func GetHttpClient

func GetHttpClient(configuration *Settings, useProxy bool) *http.Client

GetHttpClient creates the HTTP client and return it

func GetIPFromInterface

func GetIPFromInterface(configuration *Settings) (string, error)

GetIPFromInterface gets IP address from the specific interface

func GetIPOnline

func GetIPOnline(configuration *Settings) (string, error)

GetIPOnline gets public IP from internet

func LoadSettings

func LoadSettings(configPath string, settings *Settings) error

LoadSettings -- Load settings from config file

func ResolveDNS

func ResolveDNS(hostname, resolver, ipType string) (string, error)

ResolveDNS will query DNS for a given hostname.

func SaveToInfluxDB

func SaveToInfluxDB(configuration *Settings, domain, currentIP string) error

SaveToInfluxDB logs to influx if IP is changed

func SendMailNotify

func SendMailNotify(configuration *Settings, domain, currentIP string) error

SendMailNotify sends mail notify if IP is changed

func SendNotify

func SendNotify(configuration *Settings, domain, currentIP string) error

SendNotify sends notify if IP is changed

func SendSlackNotify

func SendSlackNotify(configuration *Settings, domain, currentIP string) error

SendSlack sends slack if IP is changed

func SendTelegramNotify

func SendTelegramNotify(configuration *Settings, domain, currentIP string) error

SendTelegramNotify sends notify if IP is changed

Types

type Domain

type Domain struct {
	DomainName string   `json:"domain_name"`
	SubDomains []string `json:"sub_domains"`
}

Domain struct

type InfluxNotify

type InfluxNotify struct {
	Enabled        bool   `json:"enabled"`
	INFLUXServer   string `json:"influx_server"`
	INFLUXUsername string `json:"influx_username"`
	INFLUXPassword string `json:"influx_password"`
	INFLUXPort     int    `json:"influx_port"`
	SendTo         string `json:"send_to"`
}

InfluxNotify Notify struct for Influx storage

type MailNotify

type MailNotify struct {
	Enabled      bool   `json:"enabled"`
	SMTPServer   string `json:"smtp_server"`
	SMTPUsername string `json:"smtp_username"`
	SMTPPassword string `json:"smtp_password"`
	SMTPPort     int    `json:"smtp_port"`
	SendTo       string `json:"send_to"`
}

Notify struct for SMTP notification

type Notify

type Notify struct {
	Telegram TelegramNotify `json:"telegram"`
	Mail     MailNotify     `json:"mail"`
	Slack    SlackNotify    `json:"slack"`
	Influx   InfluxNotify   `json:"influx"`
}

Notify struct

type Settings

type Settings struct {
	Provider    string   `json:"provider"`
	Email       string   `json:"email"`
	Password    string   `json:"password"`
	LoginToken  string   `json:"login_token"`
	Domains     []Domain `json:"domains"`
	IPUrl       string   `json:"ip_url"`
	IPV6Url     string   `json:"ipv6_url"`
	Interval    int      `json:"interval"`
	UserAgent   string   `json:"user_agent,omitempty"`
	LogPath     string   `json:"log_path"`
	Socks5Proxy string   `json:"socks5_proxy"`
	Notify      Notify   `json:"notify"`
	IPInterface string   `json:"ip_interface"`
	IPType      string   `json:"ip_type"`
	Resolver    string   `json:"resolver"`
	UseProxy    bool     `json:"use_proxy"`
}

Settings struct

type SlackNotify

type SlackNotify struct {
	Enabled     bool   `json:"enabled"`
	BotApiToken string `json:"bot_api_token"`
	Channel     string `json:"channel"`
	MsgTemplate string `json:"message_template"`
	UseProxy    bool   `json:"use_proxy"`
}

Notify struct for slack notification

type TelegramNotify

type TelegramNotify struct {
	Enabled     bool   `json:"enabled"`
	BotApiKey   string `json:"bot_api_key"`
	ChatId      string `json:"chat_id"`
	MsgTemplate string `json:"message_template"`
	UseProxy    bool   `json:"use_proxy"`
}

Notify struct for telegram notification

Directories

Path Synopsis
cmd
he
Package resolver is a simple dns resolver based on miekg/dns
Package resolver is a simple dns resolver based on miekg/dns

Jump to

Keyboard shortcuts

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