A DNS management toolkit built on top of dnscontrol, providing easy-to-use commands for fetching, managing, and backing up DNS records.
- Fetch existing DNS records from Cloudflare
- Create timestamped backups of DNS records
- Preview DNS changes before applying them
- Validate DNS configurations
- Apply DNS changes with safety confirmations
- Export records in JSON or YAML format
- Extensible design for multiple DNS providers (currently supports Cloudflare)
- dnscontrol: See INSTALL.md for installation instructions
- jq: Required for JSON processing (install via
brew install jqon macOS orapt-get install jqon Linux) - curl: For API calls (usually pre-installed)
Optional:
- yq: For YAML output support
- python3: Alternative for YAML conversion
-
Clone this repository:
git clone <repository-url> cd dnskit
-
Install dnscontrol (see INSTALL.md)
-
Set up your Cloudflare credentials:
cp config/creds.json.template config/creds.json # Edit config/creds.json with your Cloudflare API token and account ID -
Add dnskit to your PATH:
export PATH="$PATH:$(pwd)/bin" # Or add to your ~/.bashrc or ~/.zshrc
Create config/creds.json from the template:
{
"cloudflare": {
"TYPE": "CLOUDFLAREAPI",
"accountid": "your-cloudflare-account-id",
"apitoken": "your-cloudflare-api-token"
}
}To get your Cloudflare API token:
- Log in to Cloudflare Dashboard
- Go to My Profile > API Tokens
- Create a token with Zone:Read and Zone:DNS:Edit permissions
Create config/dnsconfig.js to define your DNS records. See config/dnsconfig.js.sample for examples.
Example:
var REG_NONE = NewRegistrar("none");
var DSP_CLOUDFLARE = NewDnsProvider("cloudflare");
D("example.com", REG_NONE, DnsProvider(DSP_CLOUDFLARE),
A("@", "192.0.2.1"),
A("www", "192.0.2.1"),
CNAME("blog", "example.com."),
MX("@", 10, "mail.example.com."),
TXT("@", "v=spf1 include:_spf.example.com ~all")
);Test your Cloudflare API credentials:
dnskit testThis verifies that your API token is working and shows a sample of your zones.
List all zones in your Cloudflare account:
dnskit listFetch and display DNS records from Cloudflare in raw JSON format:
# Fetch records in JSON format (default)
dnskit fetch example.com
# Fetch records in YAML format
dnskit fetch example.com -f yaml
# Save to a file
dnskit fetch example.com -o records.jsonExport DNS records to dnscontrol format (JavaScript) that you can edit and reapply:
# Export to default location (config/dnsconfig.js)
dnskit export example.com
# Export to custom file
dnskit export example.com -o my-dns-config.js
# Append multiple domains to one file
dnskit export example.com -o config/dnsconfig.js
dnskit export another-domain.com -o config/dnsconfig.js -aThis creates a dnsconfig.js file that you can:
- Edit to add/remove/modify DNS records
- Validate with
dnskit validate - Preview changes with
dnskit preview - Apply with
dnskit apply
Create timestamped backups:
# Backup to default directory (./backups)
dnskit backup example.com
# Backup to custom directory
dnskit backup example.com -d /path/to/backups
# Backup in YAML format
dnskit backup example.com -f yamlPreview what changes would be made without applying them:
dnskit previewThis is useful to verify your changes before applying them to production.
Validate your DNS configuration and credentials:
dnskit validateThis checks:
- JSON syntax in credentials file
- Cloudflare API credentials validity
- DNS configuration syntax
Apply DNS changes to Cloudflare:
# Interactive mode (asks for confirmation)
dnskit apply
# Skip confirmation
dnskit apply --forceWARNING: This modifies your live DNS records. Always run dnskit preview first!
If you want to manage existing DNS records with dnskit:
# 1. Test your connection
dnskit test
# 2. Export existing DNS to dnscontrol format
dnskit export example.com
# 3. Review the generated configuration
cat config/dnsconfig.js
# 4. Make changes to the file
vim config/dnsconfig.js
# 5. Preview what will change
dnskit preview
# 6. Apply the changes
dnskit applyTypical workflow for managing DNS:
# 1. Create a backup before making changes
dnskit backup example.com
# 2. Edit your DNS configuration
vim config/dnsconfig.js
# 3. Validate the configuration
dnskit validate
# 4. Preview the changes
dnskit preview
# 5. Apply the changes
dnskit applyExport and manage multiple domains in one configuration file:
# Export all your domains
dnskit export example.com -o config/dnsconfig.js
dnskit export another-domain.com -o config/dnsconfig.js -a
dnskit export third-domain.com -o config/dnsconfig.js -a
# Now you can manage all domains together
dnskit preview
dnskit apply| Command | Description |
|---|---|
dnskit test |
Test Cloudflare API connection and credentials |
dnskit list |
List all zones in your Cloudflare account |
dnskit fetch <domain> |
Fetch DNS records in JSON/YAML format |
dnskit export <domain> |
Export DNS records to dnscontrol format (editable) |
dnskit backup <domain> |
Create timestamped backup of DNS records |
dnskit preview |
Preview DNS changes without applying |
dnskit apply |
Apply DNS changes to Cloudflare |
dnskit validate |
Validate DNS configuration |
dnskit version |
Show version information |
dnskit help |
Show help message |
dnskit/
├── bin/ # CLI executables
│ ├── dnskit # Main CLI entry point
│ ├── dnskit-fetch
│ ├── dnskit-backup
│ ├── dnskit-preview
│ ├── dnskit-apply
│ └── dnskit-validate
├── lib/ # Helper libraries
│ ├── common.sh # Common functions
│ └── cloudflare.sh # Cloudflare-specific functions
├── config/ # Configuration files
│ ├── creds.json.template
│ ├── dnsconfig.js.sample
│ └── .gitignore
├── examples/ # Example configurations
├── backups/ # Default backup directory (created automatically)
├── INSTALL.md # Installation instructions
└── README.md # This file
Install dnscontrol following the instructions in INSTALL.md.
Copy the template and fill in your credentials:
cp config/creds.json.template config/creds.jsonInstall jq:
- macOS:
brew install jq - Linux:
apt-get install jqoryum install jq
Make sure:
- The domain is added to your Cloudflare account
- Your API token has the correct permissions
- The domain name is spelled correctly
- Support for additional DNS providers (AWS Route53, Google Cloud DNS, etc.)
- Batch operations for multiple domains
- DNS record templates
- Integration tests
- Migration to Go for better performance (if needed)
Contributions are welcome! Feel free to submit issues and pull requests.
See LICENSE file for details.