- Rust 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| .github/workflows | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| docker-compose.yml | ||
| dockerfile | ||
| example.env | ||
| GitVersion.yml | ||
| LICENSE | ||
| readme.md | ||
Porkbun Dynamic DNS Updater (Rust & Docker)
This project provides a lightweight and efficient Dynamic DNS (DDNS) client written in Rust, designed to update DNS A records on Porkbun.com for your domains and subdomains. It's built to run continuously as a background task, ideal for deployment in a Docker container.
Features
-
IPv4 Support: Automatically detects and updates your public IPv4 address.
-
Automatic Record Creation: If an A record for a specified subdomain does not exist, the application will create it.
-
Multiple Subdomain Support: Configurable to update one or more subdomains, including the root/base domain.
-
Continuous Operation: Runs in a loop with a configurable check interval, ensuring your DNS records are always up-to-date.
-
Environment Variable Configuration: All sensitive information and settings are managed securely via environment variables.
-
Logging: Provides clear log output for IP changes and operational status.
-
Docker Ready: Includes a
Dockerfileanddocker-compose.ymlfor easy containerized deployment.
Prerequisites
Before you begin, ensure you have the following installed:
-
Docker and Docker Compose: For containerized deployment.
-
Rust (Optional): If you plan to build and run the application manually outside of Docker.
Setup
-
Project Structure: Ensure your project directory is structured as follows:
porkbun_ddns_updater/ ├── src/ │ └── main.rs ├── Cargo.toml ├── Cargo.lock ├── Dockerfile └── docker-compose.yml -
Porkbun API Keys: You will need to generate an API Key and Secret Key from your Porkbun account:
-
Log in to Porkbun.
-
Go to
Account->API Access. -
Create a new API Key. Make sure to save your Secret Key immediately, as it will only be shown once.
-
Ensure that API access is enabled for the specific domain(s) you intend to update under
Domain Management->Detailsfor each domain.
-
-
Create a
.envfile Create a file named.envin the same directory as yourdocker-compose.ymland populate it with your Porkbun API credentials and domain details. This keeps your sensitive information out of thedocker-compose.ymlitself.PORKBUN_API_KEY="your_api_key_here" PORKBUN_SECRET_API_KEY="your_secret_api_key_here" PORKBUN_DOMAIN="yourdomain.com" PORKBUN_SUBDOMAIN="www,blog" # Comma-separated list of subdomains. # - Use "" for only the base domain (e.g., "yourdomain.com"). # - Use ",www,blog" to include the base domain and subdomains. PORKBUN_CHECK_INTERVAL_SECONDS="300" # Interval in seconds between IP checks (e.g., 300 for 5 minutes) -
Configure
docker-compose.ymlEnsure yourdocker-compose.ymlis configured to use the.envfile:# docker-compose.yml version: '3.8' services: porkbun-ddns: build: . container_name: porkbun-ddns-updater env_file: - .env environment: PORKBUN_API_KEY: ${PORKBUN_API_KEY} PORKBUN_SECRET_API_KEY: ${PORKBUN_SECRET_API_KEY} PORKBUN_DOMAIN: ${PORKBUN_DOMAIN} PORKBUN_SUBDOMAIN: ${PORKBUN_SUBDOMAIN} PORKBUN_CHECK_INTERVAL_SECONDS: ${PORKBUN_CHECK_INTERVAL_SECONDS} restart: unless-stopped logging: driver: "json-file" options: max-size: "10m" max-file: "5"
Running the Application
With Docker Compose (Recommended)
This is the easiest way to run the application as a background service.
-
Navigate to the root directory of your project (where
docker-compose.ymlis located) in your terminal. -
Build the Docker image and start the container in detached mode:
docker compose up -d --build-
docker compose up: Starts the services defined indocker-compose.yml. -
-d: Runs the container in detached mode (in the background). -
--build: Builds the Docker image from theDockerfilebefore starting. Use this for the first run or after making changes to the Rust code orDockerfile.
-
-
Check Logs: To view the real-time logs of your running container:
docker logs porkbun-ddns-updater -f(Press
Ctrl+Cto exit the log stream.) -
Stop the Container: To stop the running container:
docker compose down
Manually (Without Docker)
If you prefer to run the application directly on your host machine (requires Rust installed):
-
Build the Project: Navigate to your project root and build the release binary:
cargo build --release -
Set Environment Variables: Before running, you must set the required environment variables in your shell. Replace the placeholders with your actual values:
export PORKBUN_API_KEY="your_api_key_here" export PORKBUN_SECRET_API_KEY="your_secret_api_key_here" export PORKBUN_DOMAIN="yourdomain.com" export PORKBUN_SUBDOMAIN="www,blog" # Or "" for root, or ",www" for root and www export PORKBUN_CHECK_INTERVAL_SECONDS="300"(For persistent environment variables, refer to your operating system's documentation.)
-
Run the Application:
cargo run --releaseThe application will start logging output to your console.
Troubleshooting
-
"PORKBUN_API_KEY environment variable not set.": Ensure all required environment variables are correctly set in your
docker-compose.ymlor your shell environment. -
"Failed to retrieve A record from Porkbun: Invalid API Key": Double-check your
PORKBUN_API_KEYandPORKBUN_SECRET_API_KEYfor typos. Also, ensure API access is enabled for your domain in the Porkbun dashboard. -
"No existing A record found for...": This script only updates existing A records. You need to manually create the initial A record(s) for your domain/subdomain(s) on Porkbun.
-
"No A record found for...": If an A record is not found, the application will attempt to create it. If creation fails, check Porkbun API permissions and ensure the domain is correctly configured.
-
No IP change detected: The script will only log an update if your public IP address has actually changed. If your IP is stable, it will simply log that no update is needed.