CoreDNS旨在成为一个快速灵活的DNS服务器。
CoreDNS目前支持的行为,括号里面的英文表示插件:
官方下载安装包,执行出错(估计是coreDNS不支持MAC的m1芯片)
直接安装brew
brew tap "coredns/deployment" "https://github.com/coredns/deployment"
brew install coredns
brew services start coredns
备注:在我的电脑上MAC M1 brew services start coredns启动无效
直接输入coredns 反而有效
coredns
.:53
CoreDNS-1.8.6
darwin/arm64, go1.17.2,
显示了端口为43,软件版本为1.8.6, 系统硬件架构为darwin/arm64, go的语言版本1.17.2
安装以后文件目录
/opt/homebrew/Cellar/coredns/1.8.6
新建一个Corefile文件
内容如下
.:53 {
forward . 114.114.114.114 223.5.5.5
log
errors
whoami
}
启动 coredns -conf Corefile
新开一个命令行窗口
dig @localhost -p 53 a www.baidu.com
; <<>> DiG 9.10.6 <<>> @localhost -p 53 a www.baidu.com
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37341
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com. IN A
;; ANSWER SECTION:
www.baidu.com. 240 IN CNAME www.a.shifen.com.
www.a.shifen.com. 240 IN A 220.181.38.150
www.a.shifen.com. 240 IN A 220.181.38.149
;; Query time: 24 msec
;; SERVER: ::1#53(::1)
;; WHEN: Wed Sep 21 10:11:10 CST 2022
;; MSG SIZE rcvd: 149
coreDNS命令行窗口的控制台显示日志
.:53
CoreDNS-1.8.6
darwin/arm64, go1.17.2,
[INFO] [::1]:58726 - 53063 "A IN www.baidu.com. udp 42 false 4096" NOERROR qr,rd,ra 138 0.037228334s
networksetup -setdnsservers Wi-Fi 127.0.0.1
这个命令行一输入,本地机器就会使用coreDNS的解析。我们输入网址www.baidu.com
控制台将显示
[INFO] 127.0.0.1:28258 - 61059 "A IN www.baidu.com. udp 31 false 512" NOERROR qr,rd,ra 138 0.009493709s
[INFO] 127.0.0.1:11159 - 39202 "A IN dss1.bdstatic.com. udp 35 false 512" NOERROR qr,rd,ra 126 0.01048675s
[INFO] 127.0.0.1:31195 - 48054 "HTTPS IN www.baidu.com. udp 31 false 512" NOERROR qr,rd,ra 164 0.009485041s
[INFO] 127.0.0.1:57347 - 6177 "A IN dss0.bdstatic.com. udp 35 false 512" NOERROR qr,rd,ra 126 0.010911875s
[INFO] 127.0.0.1:52575 - 46907 "A IN dss1.bdstatic.com. udp 35 false 512" NOERROR qr,rd,ra 126 0.012114125s
[INFO] 127.0.0.1:60708 - 48398 "HTTPS IN dss1.bdstatic.com. udp 35 false 512" NOERROR qr,rd,ra 176 0.012130291s
如果想取消,自己手工去修改电脑网络里的DNS设置即可
.:53 {
forward . 114.114.114.114 223.5.5.5
log
errors
whoami
# hosts插件,不支持泛域名解析。
hosts {
127.0.0.1 www.baidu.com
127.0.0.1 abc.com
# ttl
ttl 60
# 重载hosts配置
reload 10s
# 继续执行
fallthrough
}
}
我们输入www.baidu.com将转到了本地
这个功能和我们修改本地etc/hosts文件作用一样
#coredns -plugins
Server types:
dns
Caddyfile loaders:
flag
default
Other plugins:
dns.acl
dns.any
dns.auto
dns.autopath
dns.azure
dns.bind
dns.bufsize
dns.cache
dns.cancel
dns.chaos
dns.clouddns
dns.debug
dns.dns64
dns.dnssec
dns.dnstap
dns.erratic
dns.errors
dns.etcd
dns.file
dns.forward
dns.geoip
dns.grpc
dns.header
dns.health
dns.hosts
dns.k8s_external
dns.kubernetes
dns.loadbalance
dns.local
dns.log
dns.loop
dns.metadata
dns.minimal
dns.nsid
dns.pprof
dns.prometheus
dns.ready
dns.reload
dns.rewrite
dns.root
dns.route53
dns.secondary
dns.sign
dns.template
dns.tls
dns.trace
dns.transfer
dns.whoami
on
https://zhuanlan.zhihu.com/p/92081428
https://www.cnblogs.com/xiongwei/p/16289329.html