Skip to content

cpjet64/CurtsDDNS

Repository files navigation

Curt's Dynamic DNS Updater

Curt's Dynamic DNS Updater is a Python script designed to update DNS records automatically for dynamic IP addresses. This solution supports multiple DNS providers including Cloudflare.

Features

  • Automatic IP detection and DNS record update
  • Support for multiple DNS providers
  • Configurable via an INI file
  • Runs continuously with a configurable check interval
  • Optional self‑updater that pulls new versions from Git
  • Rotating log file with configurable path, level, and size

Requirements

  • Python 3.12
  • requests library

Installation

Installing Python 3.12 on Debian-based Systems

  1. Update your package list:

    sudo apt update
  2. Install dependencies:

    sudo apt install -y software-properties-common
  3. Add the deadsnakes PPA:

    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt update
  4. Install Python 3.12:

    sudo apt install -y python3.12 python3.12-venv python3.12-dev

Setting Up the Project

  1. Clone the repository:

    git clone https://github.com/cpjet64/curtsddns.git
    cd curtsddns
  2. Create a virtual environment:

    python3.12 -m venv venv
  3. Activate the virtual environment:

    source venv/bin/activate
  4. Install the required dependencies:

    pip install requests
  5. Configure your DNS settings in the config.ini file using config.ini.example as a template:

    cp config.ini.example config.ini

Configuration

The config.ini file should be structured as follows:

[settings]
DNS_PROVIDER = cloudflare
CHECK_INTERVAL = 60               ; seconds between DNS checks
AUTO_UPDATE = false               ; enable/disable Git-based self-update
AUTO_UPDATE_INTERVAL = 3600       ; seconds between update checks

[logging]
LOG_FILE = curtsddns.log          ; path to log file (absolute or relative)
LOG_LEVEL = INFO                  ; DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_MAX_BYTES = 1048576           ; max size in bytes before rotation
LOG_BACKUP_COUNT = 5              ; how many rotated files to keep

[cloudflare]
CLOUDFLARE_API_TOKEN = your_cloudflare_api_token
CLOUDFLARE_ZONE_ID = your_cloudflare_zone_id
CLOUDFLARE_RECORD_NAME = your_dns_record_name

Usage

To start the script, simply run:

python curtsddns.py

Systemd Service

For continuous operation, you can set up a systemd service:

Copy the curtsddns.service file to /etc/systemd/system/ and then modify as needed:

sudo cp curtsddns.service /etc/systemd/system/
sudo nano /etc/systemd/system/curtsddns.service

OR

Have the file created for you using the current user and file location:

echo "[Unit]
Description=Curt's Dynamic DNS Updater Service
After=network.target

[Service]
Type=simple
User=$(whoami)
WorkingDirectory=$(pwd)
ExecStart=$(pwd)/venv/bin/python $(pwd)/curtsddns.py
Restart=on-failure

[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/curtsddns.service

Reload the systemd daemon:

sudo systemctl daemon-reload

Enable and start the service:

sudo systemctl enable curtsddns
sudo systemctl start curtsddns

Files

  • curtsddns.py: Main script for updating DNS records.
  • cloudflare_module.py: Module for handling Cloudflare DNS updates.
  • config.ini: Configuration file (create from config.ini.example).
  • config.ini.example: Example configuration file.
  • curtsddns.service: Systemd service file for running the script as a service.
  • Dockerfile:Docker configuration file.

Dockerizing the App

To run Curt's Dynamic DNS Updater in a Docker container, follow these steps:

Prerequisites

  • Docker installed on your system

Docker Setup

  1. Clone the repository:

    git clone https://github.com/cpjet64/curtsddns.git
    cd curtsddns
  2. Configure your DNS settings in the config.ini file using config.ini.example as a template:

    cp config.ini.example config.ini

    Modify your config.ini according to your environment:

    nano config.ini

    The config.ini file should be structured as follows:

    [settings]
    DNS_PROVIDER = cloudflare
    CHECK_INTERVAL = 60
    AUTO_UPDATE = false
    AUTO_UPDATE_INTERVAL = 3600
    
    [logging]
    LOG_FILE = curtsddns.log
    LOG_LEVEL = INFO
    LOG_MAX_BYTES = 1048576
    LOG_BACKUP_COUNT = 5
    
    [cloudflare]
    CLOUDFLARE_API_TOKEN = your_cloudflare_api_token
    CLOUDFLARE_ZONE_ID = your_cloudflare_zone_id
    CLOUDFLARE_RECORD_NAME = your_dns_record_name
  3. Build the Docker image:

    docker build -t curtsddns .
  4. Run the Docker container:

    docker run -d --restart unless-stopped --name curtsddns -v $(pwd)/config.ini:/app/config.ini curtsddns
    • -d runs the container in detached mode.
    • --name curtsddns gives the container a name.
    • -v $(pwd)/config.ini:/app/config.ini mounts the config.ini file from the host to the container.

Managing the Docker Container

  • To stop the container:

    docker stop curtsddns
  • To start the container:

    docker start curtsddns
  • To view the container logs:

    docker logs curtsddns
  • To remove the container:

    docker rm curtsddns

Notes

  • Ensure that the config.ini file is properly configured before running the container.
  • You can customize the Dockerfile and Docker run command to suit your specific needs.

By following these steps, you can easily run Curt's Dynamic DNS Updater in a Docker container, simplifying deployment and management.

Auto‑update behavior

Curt's DDNS can optionally keep itself up to date by pulling the latest changes from the Git remote and restarting the process.

  • The auto‑updater is disabled by default. Enable it via config.ini:
    [settings]
    AUTO_UPDATE = true
    AUTO_UPDATE_INTERVAL = 3600
  • Requirements:
    • The app must be running from a git clone of this repository.
    • A remote named origin must point to your GitHub repo.
    • git must be installed and available in PATH for the service user.
  • Behavior:
    • Every AUTO_UPDATE_INTERVAL seconds, the app compares the local HEAD to origin/HEAD.
    • If different, it runs git pull --ff-only and then re‑execs the Python process (os.execv) so the new code is loaded.
    • All actions and failures are logged via the configured logger.
  • Recommendation:
    • Use an interval of at least 1 hour (3600) to avoid unnecessary traffic.

If auto‑update fails (no network, git error, etc.), the app logs a warning/error and continues running with the existing code.

Logging and rotation

The service uses Python's logging with a RotatingFileHandler:

  • Configuration (in config.ini):
    [logging]
    LOG_FILE = /var/log/curtsddns.log
    LOG_LEVEL = INFO
    LOG_MAX_BYTES = 1048576
    LOG_BACKUP_COUNT = 5
  • LOG_FILE can be absolute (e.g. /var/log/curtsddns.log) or relative to the app directory.
  • When the log file reaches LOG_MAX_BYTES, it rotates and keeps up to LOG_BACKUP_COUNT old files.
  • Logs are written both to the file and to stdout/stderr, so they also appear in journalctl when run under systemd.

Make sure the service user has write permissions to the directory containing LOG_FILE (e.g. chown or adjust the path).

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

Contact

For support or inquiries, please contact Curt at curt@curtpme.com.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors