本文同步發表 https://nevertired.nctu.me/2020/02/01/coredns-cloud-native-dns/
前面介紹過 MaraDNS
今天來說 CoreDNS
同樣支援跨平台、opensource
主打 Cloud Native DNS
其更過人的長處在於
MaraDNS 稍微有點複雜
CoreDNS 更進一步簡化
並支援 Plugins
想要什麼,就有什麼
CoreDNS 官網 https://coredns.io/
優點
節錄自 https://github.com/coredns/coredns
Serve zone data from a file; both DNSSEC (NSEC only) and DNS are supported (file and auto).
Retrieve zone data from primaries, i.e., act as a secondary server (AXFR only) (secondary).
Sign zone data on-the-fly (dnssec).
Load balancing of responses (loadbalance).
Allow for zone transfers, i.e., act as a primary server (file).
Automatically load zone files from disk (auto).
Caching of DNS responses (cache).
Use etcd as a backend (replacing SkyDNS) (etcd).
Use k8s (kubernetes) as a backend (kubernetes).
Serve as a proxy to forward queries to some other (recursive) nameserver (forward).
Provide metrics (by using Prometheus) (metrics).
Provide query (log) and error (errors) logging.
Integrate with cloud providers (route53).
Support the CH class: version.bind and friends (chaos).
Support the RFC 5001 DNS name server identifier (NSID) option (nsid).
Profiling support (pprof).
Rewrite queries (qtype, qclass and qname) (rewrite and template).
Block ANY queries (any).
開始使用
進入官網按下 Download 就會發現 CoreDNS 都已經編譯好各種平台了,貼心啊
以 windows 為例
下載後僅有一個執行檔
直接執行預設就有 whoami and log 兩個 plugins
建立 config
在同目錄下建立 Corefile
# 監聽 53 port
.:53 {
forward . 8.8.8.8:53
errors
log
}
# 建立 example.org domain
# 相關紀錄位於 db.example.org 格式請參考 https://docs.cloud.oracle.com/en-us/iaas/Content/DNS/Reference/formattingzonefile.htm
example.org {
file db.example.org
errors
log
}
建立 db.example.org flie
格式請參考 RFC 1035 https://docs.cloud.oracle.com/en-us/iaas/Content/DNS/Reference/formattingzonefile.htm
example.org. IN SOA dns.example.org. domains.example.org. (
2012062701 ; serial
300 ; refresh
1800 ; retry
14400 ; expire
300 ) ; minimum
@ IN NS dns.example.com.
@ 42000 IN A 127.0.0.1
@ 42000 IN A 127.0.0.2
@ 42000 IN A 127.0.0.3
api 42000 IN CNAME sample.service.dns.example.de.
www 42000 IN CNAME sample.service.dns.example.de.
blog 42000 IN CNAME sample.service.dns.example.de.
@ 3600 IN MX 1 ASPMX1.L.google.com.
@ 3600 IN MX 1 ASPMX2.L.google.com.
@ 3600 IN MX 1 ASPMX3.L.google.com.
@ 300 IN TXT "v=spf1 include:_spf.google.com ~all"
執行、測試
.\coredns.exe
C:UsersNB>nslookup
> server 127.0.0.1
預設伺服器: [127.0.0.1]
Address: 127.0.0.1
> example.org
伺服器: [127.0.0.1]
Address: 127.0.0.1
名稱: example.org
Addresses: 127.0.0.1
127.0.0.2
127.0.0.3