Skip to main content

CoreDNS - Docker Compose, Open Source DNS server. Troubleshooting .local domain resoluation on Ubuntu server 22.04

424 words·
CoreDNS DNS Docker-Compose
Table of Contents

CoreDNS is an open source DNS server written in GO.

CoreDNS
#

Prerequisites
#

For the CoreDNS Docker Compose setup I use an Ubuntu 22.04 server with the following IP: 192.168.30.11

Folder Structure
#

# Create folder structure
sudo mkdir -p /opt/coredns && cd /opt/coredns

Docker Compose
#

# Create Docker Compose file
sudo vi docker-compose.yml
version: '3.9'
services:

  coredns:
    image: coredns/coredns:latest
    volumes:
      - ./Corefile:/etc/coredns/Corefile
    ports:
      - "192.168.30.11:53:53/udp"
      - "192.168.30.11:53:53/tcp"
    restart: unless-stopped
    command: -conf /etc/coredns/Corefile

Note: It’s necessary to bind the DNS port to a specific interface IP, otherwise you’ll get the following error because the port is already in use:

Error response from daemon: driver failed programming external connectivity on endpoint coredns-coredns-1
(05ef873c948d9452c73fdb2904c2902fcb93b8d7fee7b00887a56d00c938bc66): Error starting userland proxy: listen tcp4 0.0.0.0:53: bind: address already in use

Corefile
#

  • Create a file named “Corefile” where the DNS entries are defined
# Create Corefile
sudo vi Corefile
.:53 {
    hosts { # Define A-Records
        192.168.30.90 vm1.jklug.local.
        192.168.30.91 vm2.jklug.local.
        192.168.30.92 vm3.jklug.local.
        fallthrough
    }
    forward . 1.1.1.1 8.8.8.8 # Define external DNS servers
    cache
    log
    errors
}
  • .:53 CoreDNS will listen on all interfaces at port 53, the standard port for DNS.

  • fallthrough Allows DNS queries to continue to the next plugin if no match is found in the hosts file.

  • forward Forward any queries that are not resolved in the hosts block to external DNS servers for resolution.

  • cache Enables caching of DNS query results to improve resolution speed for frequently accessed domains.

  • log Enables logging of DNS queries to help with debugging and monitoring.

  • errors Logs any errors.


Start Container
#

# Create / start the Docker container
sudo docker compose up -d

Testing
#

# Test the DNS resolution from the CoreDNS server
dig @192.168.30.11 vm1.jklug.local

# Test the DNS resolution from the CoreDNS server: Define port for troubleshooting
dig @192.168.30.11 -p 53 vm1.jklug.local

# Alternative command
nslookup vm1.jklug.local 192.168.30.11

Troubleshooting
#

.local Domain Resoluation
#

With Ubuntu server 22.04 I had the problem that I could not resolve .local domain names, neither from CoreDNS nor from my router, although it worked fine with Debian 12. I solved the problem as follows:

# Remove the original symlink to /run/systemd/resolve/stub-resolv.conf (Stub Resolver)
sudo rm -f /etc/resolv.conf

# Create a new symlink to /run/systemd/resolve/resolv.conf (Direct Resolution)
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

# Reboot the server
sudo reboot

The stub resolver provided by systemd-resolved at 127.0.0.53 acts as a local caching DNS proxy, in return direct resolution involves DNS queries being sent straight to the configured upstream DNS servers.


Links #

# Official Documentation
https://coredns.io/manual/toc/#installation

# DockerHub
https://hub.docker.com/r/coredns/coredns