27b7187f3abdc632ecd43330de4e2686688fc8ad
CoreDNS NetBox Sync
This container automates the generation of DNS zone files for CoreDNS (or BIND) by synchronizing data from NetBox. It fetches IPAM data (active IPs with DNS names) and DNS Plugin records.
Features
- Automated Synchronization: Periodically fetches data from NetBox (Default: 10 minutes).
- Fail-Safe Operation: If NetBox is unreachable or returns errors, the existing zone files are preserved to prevent
NXDOMAINissues. - Dual Zone Support: Generates both Forward and Reverse (PTR) zones.
- Intelligent Fallback: Automatically configures a fallback Nameserver if no NS records are defined in NetBox.
Configuration
Configuration is handled entirely via environment variables.
Required Variables
| Variable | Description |
|---|---|
NETBOX_URL |
The full URL to the NetBox instance (e.g., http://netbox.local). |
NETBOX_TOKEN |
The API Token for authentication (Read-Only permissions are sufficient). |
Optional Variables
| Variable | Default | Description |
|---|---|---|
REFRESH_INTERVAL |
600 |
Synchronization interval in seconds. |
ZONE_NAME |
klenzel.net |
The DNS zone name to manage. |
REVERSE_ZONE_NAME |
172.in-addr.arpa |
The reverse lookup zone name. |
OUTPUT_FILE_FWD |
/zones/db.klenzel.net |
Path inside the container for the forward zone file. |
OUTPUT_FILE_REV |
/zones/db.reverse.arpa |
Path inside the container for the reverse zone file. |
FALLBACK_NS_HOSTNAME |
fks-01-cl-cdns |
Hostname used for NS record if none exist in NetBox. |
FALLBACK_NS_IP |
172.25.16.152 |
IP address for the fallback NS glue record. |
Usage
Docker
-
Build the image:
docker build -t local/dns-sync . -
Run with environment variables:
docker run -d \ --name klzDNS-worker \ --restart unless-stopped \ --net=container:klzDNS-coredns \ -v klzDNS-data:/zones \ -e NETBOX_URL="http://172.30.242.99" \ -e NETBOX_TOKEN="your-secret-token" \ local/dns-sync
Using a .env file
-
Create a
.envfile based on the example:cp .env.example .env # Edit .env and add your credentials -
Run the container referencing the file:
docker run -d \ --name klzDNS-worker \ --restart unless-stopped \ --net=container:klzDNS-coredns \ -v klzDNS-data:/zones \ --env-file .env \ local/dns-sync
Description
Languages
Python
94.2%
Dockerfile
5.8%