Skip to main content
  1. Techticles/

Building a Custom Dynamic DNS Updater in Go

499 words·3 mins
Table of Contents

The Problem: Dynamic IPs and Custom Domains
#

Many of us run services from home that we want to access remotely - whether it’s a personal cloud, a development environment, or just a simple website. While services like DynDNS exist, I wanted a solution that would work with my existing custom domains without paying for a static IP address from my ISP.

This led me to create dns-updater, a lightweight tool that automatically updates DNS records across multiple providers whenever your public IP changes.

The Solution: dns-updater
#

The project is open source and available on GitHub. At its core, it’s a Go application that:

  1. Detects your current public IP address
  2. Updates DNS records across supported providers (currently DigitalOcean and Google Cloud Platform)
  3. Runs in a minimal Docker container for easy deployment

Key Features
#

  • Multiple Provider Support: Works with both DigitalOcean DNS and Google Cloud Platform DNS
  • Docker-Ready: Runs in a minimal, secure container
  • YAML Configuration: Simple configuration for managing multiple domains and records
  • Lightweight: Built in Go for minimal resource usage

How It Works
#

The application follows a straightforward process:

  1. Loads configuration from a YAML file
  2. Determines the current public IP by querying an external service
  3. Connects to configured DNS providers using their APIs
  4. Updates specified DNS records if the IP has changed

Here’s a sample configuration for DigitalOcean:

doToken: "your-digitalocean-api-token"
updates:
  - domain: "example.com"
    zone: "example.com"
    records: 
      - "www"
      - "@"
    type: "A"

Security Considerations
#

Security was a key consideration in the design. The application:

  • Runs as a non-root user in Docker
  • Supports secure credential management
  • Uses HTTPS for all API communications
  • Keeps sensitive configuration separate from the application

Getting Started
#

The easiest way to get started is using Docker:

# Pull the image
docker pull ghcr.io/orkarstoft/dns-updater:latest

# Run with your config
docker run -v /path/to/config.yaml:/config.yaml ghcr.io/orkarstoft/dns-updater:latest

Future Plans
#

While the current version serves my needs well, there’s always room for improvement. Some planned features include:

  • Support for additional DNS providers
  • Webhook notifications for IP changes
  • Improved logging and monitoring
  • IPv6 support

Conclusion
#

Building dns-updater solved a specific problem I had with managing custom domains on a dynamic IP, but it’s grown into a more versatile tool that others might find useful. The project is open source, and contributions are welcome!

If you’re interested in trying it out or contributing, check out the GitHub repository. The README contains detailed setup instructions and configuration examples.

Technical Details
#

For those interested in the implementation details, the project is built using:

  • Go 1.23
  • The official DigitalOcean and Google Cloud Platform Go clients
  • Viper for configuration management
  • A multi-stage Dockerfile for minimal image size

The code is structured to make adding new DNS providers relatively straightforward through a simple interface:

type DNSImpl interface {
    UpdateRecord(*domain.DNSRequest)
}

This modular approach means you can add support for your preferred DNS provider by implementing just one interface.

Have you built something similar or have suggestions for improvement? I’d love to hear about it in the comments below!