- Introduction
- Installation
- Configuration
- Plugins
- Server Blocks
- Common Setups
- Writing Plugins
- Best Practices
CoreDNS is a flexible, extensible DNS server written in Go. Unlike traditional DNS servers, CoreDNS relies heavily on plugins to provide functionality. This modular approach allows for great customization and extensibility.
Key features of CoreDNS:
- Written in Go
- Plugin-based architecture
- Supports various protocols: DNS, DNS over TLS (DoT), DNS over HTTPS (DoH), and DNS over gRPC
- Highly configurable
There are several ways to install CoreDNS:
- Pre-compiled binaries: Available for various operating systems and architectures.
- Docker: Images are available on the public Docker hub.
- From source: Requires a working Go setup and uses Go modules for dependency management.
To test a basic CoreDNS installation:
$ ./coredns -dns.port=1053
$ dig @localhost -p 1053 a whoami.example.org
CoreDNS uses a file called Corefile
for configuration. The Corefile consists of one or more Server Blocks, each containing plugin configurations.
CoreDNS supports environment variable substitution in its configuration using the syntax {$ENV_VAR}
or {%ENV_VAR%}
.
The import
plugin allows including other configuration files or snippets.
Snippets are defined using parentheses and can be imported into other parts of the configuration:
(snip) {
prometheus
log
errors
}
. {
whoami
import snip
}
Plugins are the core of CoreDNS functionality. They can:
- Process queries
- Forward queries
- Modify responses
- Implement non-DNS functionality (e.g., metrics, health checks)
The order of plugins in the Corefile does not determine execution order. The execution order is defined in plugin.cfg
.
Example plugin configuration:
. {
chaos CoreDNS-001 [email protected]
}
Server Blocks define the zones a server is responsible for and the port it listens on. The basic syntax is:
zone:port {
plugin1
plugin2
}
Multiple zones can be specified in a single Server Block.
Use the file
plugin to serve zone data from a file:
example.org {
file db.example.org
log
}
Forward queries to other DNS servers:
. {
forward . 8.8.8.8 9.9.9.9
log
}
Use the unbound
plugin (requires recompilation) for recursive resolution:
. {
unbound
cache
log
}
To write a custom plugin:
- Create a
setup.go
file for Corefile parsing - Implement the plugin logic in a separate file (e.g.,
example.go
) - Write tests
- Create a
README.md
documenting the plugin - Include a LICENSE file
Plugins should implement the plugin.Handler
interface, which includes the ServeDNS
method.
- Use
example.org
orexample.net
in examples and tests - Implement
fallthrough
functionality when appropriate - Follow the style guide for documentation
- Include metrics and readiness reporting
- Use proper logging practices
Remember to check the CoreDNS website and GitHub repository for the most up-to-date information and best practices.
CoreDNS and OpenXPKI Setup Guide
Table of Contents
Introduction
This guide will walk you through setting up CoreDNS with OpenXPKI for certificate management, providing a robust local DNS infrastructure with valid SSL certificates.
Prerequisites
System Architecture
Step 1: Install OpenXPKI
Update your system and install dependencies:
Install OpenXPKI:
Step 2: Configure OpenXPKI
Initialize the OpenXPKI configuration:
Create a new realm (replace "Local-CA" with your desired realm name):
Edit the OpenXPKI configuration file:
Adjust the key sizes and algorithms as needed:
Configure the certificate profiles in
/etc/openxpki/config.d/realm/Local-CA/profile/
:Create or edit files for your certificate profiles (e.g., I18N_OPENXPKI_PROFILE_TLS_SERVER.yaml for server certificates).
Step 3: Set Up Root CA and Issuing CA
Generate the Root CA:
Generate the Issuing CA:
Start the OpenXPKI service:
sudo systemctl start openxpki.service sudo systemctl enable openxpki.service
Step 4: Install and Configure CoreDNS
Download and install CoreDNS:
Create CoreDNS configuration:
Add the following content:
Create a systemd service for CoreDNS:
Add the following content:
Start and enable CoreDNS:
sudo systemctl daemon-reload sudo systemctl start coredns sudo systemctl enable coredns
Step 5: Generate SSL Certificate for hostname.local
Create a certificate signing request (CSR) for hostname.local:
Submit the CSR to OpenXPKI:
openxpki-cli request create --subject "CN=hostname.local" --format pkcs10 --csr hostname.local.csr
Approve and issue the certificate:
Follow the prompts to approve and issue the certificate.
Retrieve the issued certificate:
openxpki-cli certificate get --format PEM > hostname.local.crt
Step 6: Configure Client VMs
Export the Root CA certificate:
openxpki-cli certificate get --format PEM --realm Local-CA --issuer root > root-ca.crt
Copy the Root CA certificate to client VMs:
On each client VM, install the Root CA certificate:
Configure DNS on client VMs:
Add:
Step 7: Configure SELinux (if applicable)
If you're using SELinux, follow these steps:
Generate a custom SELinux policy for CoreDNS:
Apply the custom policy:
Set correct file contexts:
Troubleshooting
sudo journalctl -u openxpki
sudo journalctl -u coredns
dig @192.168.1.10 hostname.local
openssl s_client -connect hostname.local:443 -CAfile /path/to/root-ca.crt
Advanced Usage
This guide provides a comprehensive setup for CoreDNS with OpenXPKI, allowing you to manage your own Certificate Authority and issue valid SSL certificates for your local network.