DNS forwarding
This topic describes the process to configure different DNS servers to enable DNS forwarding to Consul servers.
You can apply these operations on every node where a Consul agent is running.
Introduction
You deployed a Consul datacenter and want to use Consul DNS interface for name resolution.
When configured with default values, Consul exposes the DNS interface on port 8600
. By default, DNS is served from port 53
. On most operating systems, this requires elevated privileges. It is also common, for most operating systems, to have a local DNS server already running on port 53
.
Instead of running Consul with an administrative or root account, you can forward appropriate queries to Consul, running on an unprivileged port, from another DNS server or using port redirect.
There are two configurations for a node's DNS forwarding behavior:
- Conditional DNS forwarding: the local DNS servers are configured to forward to Consul only queries relative to the
.consul
zone. All other queries are still served via the default DNS server in the node. - Full DNS forwarding: Consul serves all DNS queries and forwards to a remote DNS server the ones outside
.consul
domain.
Conditional DNS forwarding
We recommend the conditional DNS forwarding approach. This configuration lowers the Consul agent's resource consumption by limiting the number of DNS requests it handles.
In this configuration, Consul only serves queries relative to the .consul
domain. There is no unnecessary load on Consul servers to serve queries from different domains.
This behavior is not enabled by default.
Full DNS forwarding
This approach can be useful in scenarios where the Consul agent's node is allocated limited resources and you want to avoid the overhead of running a local DNS server. In this configuration, Consul serves all DNS queries for all domains and forwards the ones outside the .consul
domain to one or more configured forwarder servers.
This behavior is not enabled by default. Consul standard configuration only resolves DNS records inside the .consul
zone. To enable DNS forwarding, you need to set the recursors option in your Consul configuration.
In this scenario, if a Consul DNS reply includes a CNAME
record pointing outside the .consul
top level domain, then the DNS reply only includes CNAME
records by default.
When recursors
is set and the upstream resolver is functioning correctly, Consul tries to resolve CNAMEs and include any records (for example, A, AAAA, PTR) for them in its DNS reply. In these scenarios, Consul is used for full DNS forwarding and is able to serve queries for all domains.
Workflow
To use DNS forwarding in Consul deployments, complete the following steps:
Configure the local DNS service to enable DNS forwarding to Consul. Follow the instructions for one of the following services:
Query the Consul DNS to confirm that DNS forwarding functions correctly.
Optionally, verify reverse DNS.
You can use the
short
option fordig
to only get the node name instead of the full output.
Troubleshooting
If your DNS server does not respond but you do get an answer from Consul, turn on your DNS server's query log to check for errors.
systemd-resolved
Enable query logging for systemd-resolved
:
Check query log:
Disable query logging:
DNS forwarding may fail if you use the default systemd-resolved
configuration and attempt to bind to 0.0.0.0
. The default configuration uses a DNS stub that listens for UDP and TCP requests at 127.0.0.53
. As a result, attempting to bind to 127.0.0.53
conflicts with the running stub. You can disable the stub as described in the Using any local resolver with systemd section to troubleshoot this problem.
Dnsmasq
To enable query log refer to Dnsmasq documentation.
In particular, look for the log-queries
and log-facility
configuration option.
When query log is enabled, it is possible to force Dnsmasq to emit a full cache dump using the SIGUSR1
signal.
BIND
Enable query log:
Check logs:
The log may show errors like this:
This error indicates that DNSSEC
is not disabled properly.
If you receive errors about network connections, verify that there are no firewall or routing problems between the servers running BIND and Consul.