CoreDNS

2019-03-07  本文已影响0人  aneirin

CoreDNS是SkyDNS的继任者,可以和很多后端(etcd,k8s等)进行通信。CoreDNS非常的灵活,它的灵活性得益于其丰富的插件 (https://coredns.io/plugins/ ),也可以写适合自己的插件。
CoreDNS可以通过UDP/TCP,TLS(RFC 7858)和gRPC监听DNS请求。
CoreDNS相较于传统DNS Server有很多特点,具体可以参考官网:https://coredns.io/
依赖CoreDNS可以很快的搭建一台DNS服务器,它的安装方法比较简单,本文主要对它的配置和若干常用插件做介绍。
默认情况下,CoreDNS加载当前工作目录下的配置文件Corefile,如果没有这个文件则加载whoami插件,然后监听53端口来响应DNS查询服务

.:53 {
    forward . 223.5.5.5:53 223.6.6.6:53
    log
}

这里用到了两个插件,分别是forward和log。forward插件将请求随机地传给后端的两个实际DNS服务器(注意forward后面的点号,它表示全部域名请求都传递到后端。如果是example.com,则表示只将匹配example.com的请求传递到后端,后端服务器最多支持15个)。log插件将查询日志打印到标准输出。

$ORIGIN example.com.     ; designates the start of this zone file in the namespace
$TTL 1h                  ; default expiration time of all resource records without their own TTL value
example.com.  IN  SOA   ns.example.com. username.example.com. ( 2007120710 1d 2h 4w 1h )
example.com.  IN  NS    ns                    ; ns.example.com is a nameserver for example.com
example.com.  IN  NS    ns.somewhere.example. ; ns.somewhere.example is a backup nameserver for example.com
example.com.  IN  MX    10 mail.example.com.  ; mail.example.com is the mailserver for example.com
@             IN  MX    20 mail2.example.com. ; equivalent to above line, "@" represents zone origin
@             IN  MX    50 mail3              ; equivalent to above line, but using a relative host name
example.com.  IN  A     192.0.2.1             ; IPv4 address for example.com
              IN  AAAA  2001:db8:10::1        ; IPv6 address for example.com
ns            IN  A     192.0.2.2             ; IPv4 address for ns.example.com
              IN  AAAA  2001:db8:10::2        ; IPv6 address for ns.example.com
www           IN  CNAME example.com.          ; www.example.com is an alias for example.com
wwwtest       IN  CNAME www                   ; wwwtest.example.com is another alias for www.example.com
mail          IN  A     192.0.2.3             ; IPv4 address for mail.example.com
mail2         IN  A     192.0.2.4             ; IPv4 address for mail2.example.com
mail3         IN  A     192.0.2.5             ; IPv4 address for mail3.example.com

Corefile:

example.com {
    file example.com
}
.:53 {
    forward . 223.5.5.5:53 223.6.6.6:53
    prometheus 10.1.1.1:9253
    log
}

重新启动CoreDNS,访问http://10.1.1.1:9253/metrics 就可以展现出dns请求相关的metrics,可以对DNS的请求数,请求延时等做监控(插件prometheus官网 https://coredns.io/plugins/metrics/
以上就是对CoreDNS的简单介绍,还有其他比较有用的插件,值得你花时间玩味。

上一篇下一篇

猜你喜欢

热点阅读