Setup a DNS server using Coredns container


I constructed DNS server with coredns

Pre-Setup

Exporses DNS query port(53) of docker host.
sudo firewall-cmd --permanent --add-port=53/udp
sudo firewall-cmd --permanent --reload

Setup

I used coredns/coredns docker image. I prepared DNS configuration (Corefile) on docker host.

Corefile ($(pwd)/dns/Corefile)
. {
    hosts {
        192.168.1.10 myServer1
        192.168.1.20 myServer2
        192.168.1.30 myServer3
        fallthrough
    }
    forward . 8.8.8.8
    reload
}
The name records that this DNS server replys for query are specified in hosts section. The DNS forwarder is specified in forward section.

Start docker container with specifying port forward (-p) and volume mount (-v) option.
docker run -d --restart=always --name coredns \
-p 53:53/udp \
-v $(pwd)/dns/:/root/ \
coredns/coredns \
-conf /root/Corefile

Operation check

Overwrite /etc/resolv.conf of docker host to use the local DNS server.

resolv.conf
#nameserver xxx.xxx.xxx.xxx <- uncomment default name server
nameserver localhost
Check whether the host is using the local DNS server or not with nslookup command.
# nslookup google.com
Server: 127.0.0.1
Address: 127.0.0.1#53

Non-authoritative answer:
Name: google.com
Address: 172.217.175.14
Name: google.com
Address: 2404:6800:4004:808::200e

Profile
I have technical job experience in enbedded software development and server side infrastructure/application engineering. I'm interested in programming and computer security.
Objective
To write down my technical knowledge in the place where I can access from anywhere. To share my program source code. To train my writing skill.
Link
  • LinkedIn (preparing)

  • Twitter

  • Facebook (preparing)

  • GitHub

  • StackOverFlow (preparing)

Archives