# CoreDNS NetBox Sync This container automates the generation of DNS zone files for CoreDNS (or BIND) by synchronizing data from [NetBox](https://github.com/netbox-community/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 `NXDOMAIN` issues. * **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 1. **Build the image:** ```bash docker build -t local/dns-sync . ``` 2. **Run with environment variables:** ```bash 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 1. Create a `.env` file based on the example: ```bash cp .env.example .env # Edit .env and add your credentials ``` 2. Run the container referencing the file: ```bash docker run -d \ --name klzDNS-worker \ --restart unless-stopped \ --net=container:klzDNS-coredns \ -v klzDNS-data:/zones \ --env-file .env \ local/dns-sync ```