Coredns 简单搭建和使用

1. 安装

因为coredns是go语言开发的,直接下载可执行包

// 下载
# wget https://github.com/coredns/coredns/releases/download/v1.1.4/coredns_1.1.4_linux_amd64.tgz

// 解压
# tar -zxvf coredns_1.1.4_linux_amd64.tgz

# ls
coredns
2. 配置使用

image

3. 启动coredns,首先安装 bind-utils
// 启动
# ./coredns -conf Corefile
mydomain.com.:1053
.:1053
2018/07/10 07:18:57 [INFO] CoreDNS-1.1.4
2018/07/10 07:18:57 [INFO] linux/amd64, go1.10.3, f78f3023
CoreDNS-1.1.4
linux/amd64, go1.10.3, f78f3023

测试 mydomain.com

// 测试 www.mydomain.com 
# dig @172.25.52.206 -p 1053 a www.mydomain.com 
; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> @172.25.52.206 -p 1053 a www.mydomain.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6468
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.mydomain.com.		IN	A

;; ANSWER SECTION:
www.mydomain.com.	3600	IN	A	127.0.0.1

;; AUTHORITY SECTION:
mydomain.com.		3600	IN	NS	a.iana-servers.net.
mydomain.com.		3600	IN	NS	b.iana-servers.net.

;; Query time: 0 msec
;; SERVER: 172.25.52.206#1053(172.25.52.206)
;; WHEN: Tue Jul 10 07:21:33 CST 2018
;; MSG SIZE  rcvd: 165

// coredns 输出
172.25.52.206:38426 - [10/Jul/2018:07:21:33 +0800] 6468 "A IN www.mydomain.com. udp 46 false 4096" NOERROR qr,aa,rd,ra 166 0.000090734s

@ 指定解析域名的dns服务器。-p 指定端口

至此基本测试完成

参考文档