AKAI TSUKI

System development or Technical something

use hosts plugin of CoreDNS

Before this post, please see
try to use CoreDNS - AKAI TSUKI
use proxy plugin of CoreDNS - AKAI TSUKI

I'd like to perform name resolution(search ipaddress) by referring hosts file.
ref. https://coredns.io/plugins/hosts/

I prepare hosts file.

[root@cent7devops ~]# vi /etc/hosts
[root@cent7devops ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.10.111 gitlab.node01.devlocal node01
172.16.10.112 node02.devlocal node02
172.16.10.113 node03.devlocal node03
172.16.10.90 devops.devlocal devops
[root@cent7devops ~]#

and I edit "Corefile" as follows:

[root@cent7devops ~]# cat Corefile
. {
    proxy . 8.8.8.8:53
    errors
    log
}

devlocal {
    hosts /etc/hosts devlocal {
      172.16.10.114 node04.devlocal
      fallthrough
    }
    errors
    log
}

[root@cent7devops ~]#

and I send a SIGUSR1 signal to the process "coredns".

[root@cent7devops ~]# ps -aef | grep coredns
root      5664  1291  0 01:49 pts/0    00:00:39 coredns -conf Corefile
root     11065  2239  0 17:45 pts/2    00:00:00 grep --color=auto coredns
[root@cent7devops ~]#
[root@cent7devops ~]# kill -SIGUSR1 5664
[root@cent7devops ~]#

Then I check reply from CoreDNS using hosts plugin.

[root@cent7devops ~]# dig -p 53 @localhost A gitlab.node01.devlocal +short
172.16.10.111
[root@cent7devops ~]# dig -p 53 @localhost A gitlab.node01.devlocal +noall +answer

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> -p 53 @localhost A gitlab.node01.devlocal +noall +answer
; (2 servers found)
;; global options: +cmd
gitlab.node01.devlocal. 3600    IN      A       172.16.10.111
[root@cent7devops ~]#

Output log is a below text.

[::1]:35747 - [13/Jul/2018:17:53:45 +0900] 27124 "A IN gitlab.node01.devlocal. udp 52 false 4096" NOERROR qr,aa,rd,ra 90 0.000058934s

Besides hosts plugin, CoreDNS can refer to dynamic settings using etcd.
I will try to use it.