System setup
I am using ubuntu 20.10 as reference system with docker and docker-compose installed.
Ubuntu and other OSes comes with systemd-resolved
installed and listening on port :53
, preventing to listen on that port. Thanks to linuxuprising.com tutorial for the steps.
To check which port is in use in your system run sudo lsof -i :53
. The response looks like
1 | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME |
Disable DNS stub listener option and set a default DNS
1 | echo 'DNSStubListener=no' | sudo tee -a /etc/systemd/resolved.conf |
Replace the default resolv.conf
file
1 | sudo cp /etc/resolv.conf /etc/resolv.conf.bak |
Finally reload the systemd-resolved service
1 | sudo service systemd-resolved restart |
Create a docker-compose file for coredns
Now create a docker-compose.yaml
file with the following content. We expose port :53
tcp and udp and use the coredns/coredns
docker image. It also mount the local folder ./config
to /etc/coredns
in the container, where we will store our configurations.
1 | version: "3.1" |
Create a ./config
folder and add in it a Corefile
file
1 | .:53 { |
See the Coredns configuration docs for more information
Add a zone file (named /etc/coredns/lan.zone from the previous example) with the references to the IPs in the network. It is based on a Wikipedia example but there are many more examples online as the format is standardized.
In the example the machine IP hosting the DNS server is 192.168.1.2
1 | @ 3600 IN SOA ns1.lan. root.lan. ( |
Now start the DNS server with docker-compose up
.
You can test the resolution with nslookup
1 | # replace the ip with your dns server ip |