Categorygithub.com/loop0/pugdns
repositorypackage
0.0.0-20240921145505-61d2f34f3d8e
Repository: https://github.com/loop0/pugdns.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

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:

ProviderWebsiteRequired Env Vars
ipifyhttps://www.ipify.orgNone
myipiohttps://www.my-ip.ioNone
viaiphttps://viaip.com.brNone

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:

ProviderWebsiteRequired Env Vars
cloudflarehttps://www.cloudflare.comPUGDNS_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.