docker run -d \
--name coredns \
-p 53:53/tcp \
-p 53:53/udp \
-v /data/coredns/hosts:/etc/hosts \
-v /data/coredns/Corefile:/Corefile \
-v /etc/resolv.conf:/etc/resolv.conf \
coredns/coredns:1.8.4
.:53 {
hosts {
# 绑定interface ip
#bind 127.0.0.1
# 先走本机的hosts(由于1.8.4版本走本机hosts无法联网问题不推荐)
# https://coredns.io/plugins/hosts/
#你需要解析的域名
hosts /hosts
# 重载hosts配置
ttl 60
reload 1m
# 继续执行
fallthrough
}
# 缓存时间ttl
cache 120
# 自动加载配置文件的间隔时间
reload 6s
forward . 114.114.114.114
# 输出日志
log
# 输出错误
errors
}
[root@node-217 coredns]# pwd
/data/coredns
[root@node-217 coredns]# cat Corefile
.:53 {
hosts {
hosts /hosts
ttl 60
reload 1m
fallthrough
}
cache 120
reload 6s
forward . 114.114.114.114
log
errors
}
需要解析的域名
[root@node-217 coredns]# cat hosts
172.20.8.28 jbjb.ok.jbjb
192.168.0.200 devgz.yaohjk.com
192.168.0.200 devboss.yaohjk.com
192.168.0.200 devlogin.yaohjk.com
192.168.0.200 devpay.yaohjk.com
192.168.0.200 devwx.yaohjk.com
[root@master156 ~]# nslookup jbjb.ok.jbjb
Server: 172.20.29.217
Address: 172.20.29.217#53
Name: jbjb.ok.jbjb
Address: 172.20.8.28
[root@master156 ~]# curl -I jbjb.ok.jbjb:50749
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
content-length: 23
server: istio-envoy
date: Fri, 27 Aug 2021 16:39:44 GMT
x-envoy-upstream-service-time: 4
root@master156 ~]# nslookup www.qq.com
Server: 172.20.29.217
Address: 172.20.29.217#53
Non-authoritative answer:
www.qq.com canonical name = ins-r23tsuuf.ias.tencent-cloud.net.
Name: ins-r23tsuuf.ias.tencent-cloud.net
Address: 121.14.77.221
Name: ins-r23tsuuf.ias.tencent-cloud.net
Address: 121.14.77.201
Name: ins-r23tsuuf.ias.tencent-cloud.net
Address: 2402:4e00:1430:1301:0:9227:79cc:76f2
Name: ins-r23tsuuf.ias.tencent-cloud.net
Address: 2402:4e00:1430:1301:0:9227:79d3:ffd1
[root@master156 ~]# ping www.qq.com
PING ins-r23tsuuf.ias.tencent-cloud.net (121.14.77.221) 56(84) bytes of data.
64 bytes from 121.14.77.221 (121.14.77.221): icmp_seq=1 ttl=54 time=4.34 ms
64 bytes from 121.14.77.221 (121.14.77.221): icmp_seq=2 ttl=54 time=4.32 ms