DEV Community

Running CoreDNS as a DNS Server in a Container

Robb Manes on February 09, 2019

If you've ever needed to or wanted to set up your own DNS server, then this is for you. I recently found myself in possession of a Raspberry Pi, a...
Collapse
 
annbob profile image
annbob

First. Thank you for the tutorial. I'm new to setting up a local DNS Server.

After some experimentation I've managed to get things working on the following system...
Ubuntu 18.04.4 LTS
Docker version 19.03.8, build afacb8b7f0
docker-compose version 1.23.1, build b02f1306
CoreDNS 1.6.9

For me to get things working correctly, I had to change the CNAME entry format from the line in the tutorial ...
server.example.com IN CNAME host.example.com
to
server.example.com. IN CNAME host
I added a '.' after 'server.example.com' and eliminated the '.example.com' from the referred record. With this format everything works as I expect on my system.
I don't know if the tutorial needs to be updated or something is different in my setup.

Thanks again for the tutorial. It was very helpful in getting things set up properly.

Collapse
 
robbmanes profile image
Robb Manes

Whoops! No, a period is necessary to indicate the end of a domain I believe. I'll fix the tutorial. Thank you for reporting it!

Collapse
 
guglieyes profile image
Ed McGuigan

Thanks for that Rob. Got me over the hump. Just want to add in PTR records and I will be golden.

I found that I needed the following for reverse lookup on a subnet 192.168.50.0/24:

In the Corefile:

50.168.192.in-addr.arpa {
file /root/db.50.168.192.in-addr.arpa
log
errors
}

And the actual database file db.50.168.192.in-addr.arpa:

**$TTL 604800
@ IN SOA dns.nibbles.hom. admin.nibbles.hom. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;

; name servers - NS records

@ IN NS dns.nibbles.hom.

; PTR records

4 IN PTR dns.nibbles.hom.
3 IN PTR sexi01.nibbles.hom.
2 IN PTR ipmi01.nibbles.hom.
**

I believe there is a plugin for CoreDNS that would take care of generating PTR records based on the regular zone file contents but I don't need that for the few servers I am running and I couldn't understand the documentation ( seems like you need a better understanding of CoreDNS than I can get in an hour ).

Collapse
 
thekillerpepsi profile image
Pepsi

Does anyone know if you can use such external plugins with the normal coreDNS-Dockerimage?

Collapse
 
mitchdresdner profile image
Mitch Dresdner

Thanks Rob, enjoyed your article on CoreDNS, nice job!

I'm planning to tinker with CoreDNS using my Raspberry Pi4's.

Was wondering if you knew whether I could use CoreDNS to allow my Pi clients to have their dynamic IP to be added to the CoreDNS db rather than be hard coded as static in the file? Perhaps during boot there's a way I could have them broadcast IP and CNAME over UDP?

Regards,

Mitch

Collapse
 
digitaldan profile image
Digital Dan • Edited

I thought I would leave this for the benefit of others who may be trying to setup CNAME records. Here are some CNAME records I have setup on my new (experimental) DNS server, ns1.topsecret.com (I have swapped out the domain name and IP addresses, but these are real examples from real queries).

topsecret.com. IN SOA ns1.topsecret.com. secure.topsecret.com. 2020060102 7200 3600 1209600 3600
topsecret.com. IN A 111.222.333.44
ns1.topsecret.com. IN A 111.222.333.44
ns2.topsecret.com. IN A 55.77.88.99
demo1.topsecret.com. IN A 111.222.333.44
demo2.topsecret.com. 120 IN A 55.77.88.99
www.demo1 IN CNAME demo1
www.demo2 IN CNAME demo2
www IN CNAME topsecret.com.

Here are some dig responses:

dig @111.222.333.44 www.demo2.topsecret.com

;; ANSWER SECTION:
www.demo2.topsecret.com. 120 IN CNAME demo2.topsecret.com.
demo2.topsecret.com. 120 IN A 55.77.88.99

dig @111.222.333.44 www.topsecret.com

;; ANSWER SECTION:
www.topsecret.com. 0 IN CNAME topsecret.com.
topsecret.com. 0 IN A 111.222.333.44

This is what you would expect.

Note, the 120 in the response for www.demo2.topsecret.com, as I have set the TTL to 120 for that particular record. Since the TTL is not set for the others, it returns 0.

Triple warning! In order to get this post to post properly, I had to swap out all of the "www"s and replaced them with "www" as otherwise this editor will actually strip them all out, and render them without the "www"!

Collapse
 
digitaldan profile image
Digital Dan • Edited

If you have a problem with the availability of port 53, because it is being used by another service, you may want to check out the following link:

github.com/dprandzioch/docker-ddns...

I found that directing traffic from 53 to 5353 worked, in which case you will have to start docker with something like this:

docker run -d --name coredns1 --restart=always --volume=/home/XXX/containers/coredns/:/root/ -p 5353:53/tcp -p 5353:53/udp coredns/coredns -conf /root/Corefile

This is covered in more detail in Aaron Hirsch's comment in the above link.

Thank you for this tutorial. Much appreciated!

Collapse
 
cecilphillip profile image
Cecil L. Phillip 🇦🇬

I'd would love to see a post on DNS service discovery with CoreDNS w/o Kubernetes :)

Collapse
 
marloncruz profile image
Marlon Cruz

Hi, I am new to dns. Can i use this for resolve dns queries from the internet.

Collapse
 
guglieyes profile image
Ed McGuigan

Yes. That is what the first section of the configuration is for.

Collapse
 
juzn01 profile image
juzn01

Great bro !

Collapse
 
anichari profile image
Ani Chari

This is awesome, works very well! Thanks for creating this.