loop0 / pugdns

pugdns updates a domain with your public ip address

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pugdns

Yoda

pugdns updates a domain on cloudflare with your public ip address.

Why

I developed this small application to relearn Go and because I needed something to update my home vpn domain with my public address when it changes.

How to use

pugdns gets the required configuration from environment variables as follows:

PUGDNS_ZONE=example.com  # The zone name where the domain will be updated
PUGDNS_DOMAIN=vpn.example.com  # The domain name to be updated with your public ip
PUGDNS_CLOUDFLARE_TOKEN=<API_TOKEN>  # The cloudflare api token with read/write access to the zone

Once you have those env vars set you can just run:

$ pugdns
2024/02/11 16:37:57 INFO Obtaining public ip
2024/02/11 16:37:57 INFO Public ip=xxx.xxx.xxx.xxx
2024/02/11 16:37:57 INFO Updating domain=vpn.example.com
2024/02/11 16:37:57 INFO Updated domain=vpn.example.com ip=xxx.xxx.xxx.xxx

Providers

Some providers will require environment variables to be set

IP Address

IP Address provider is selected via the PUGDNS_IP_PROVIDER environment variable. Default is ipify

This is the list of currently supported providers for public ip address resolution:

Provider Website Required Env Vars
ipify https://www.ipify.org None
myipio https://www.my-ip.io None

DNS

IP Address provider is selected via the PUGDNS_DNS_PROVIDER environment variable. Default is cloudflare

This is the list of currently supported providers for DNS:

Provider Website Required Env Vars
cloudflare https://www.cloudflare.com PUGDNS_CLOUDFLARE_TOKEN

How to add providers

There are currently only 2 types of providers required by pugdns to work which are defined by the following interfaces at providers.go:

type IPAddressService interface {
	GetPublicIP() (string, error)
}

type DomainService interface {
	UpdateDomain(ip string) error
}

To add a new provider you just need to implement its interface and add it to providers.go function's getIPAddressProvider or getDomainProvider. For existing provider's implementation look into the providers folder.

Usage examples

kubernetes

If you want to run pugdns in your kubernetes cluster take a look into examples/k8s-cronjob.yaml for a manifest for a cronjob that runs every hour to keep your domain update with you public ip address.

About

pugdns updates a domain with your public ip address

License:GNU General Public License v3.0


Languages

Language:Go 96.7%Language:Dockerfile 2.8%Language:Makefile 0.5%