docker部署coredns

流过昼夜 提交于 2019-12-05 07:00:51

示例:

[root@corends coredns]# cd /home/coredns/
[root@corends coredns]# ls -al
total 12
drwxr-xr-x  2 root root   61 Sep 12 11:40 .
drwxr-xr-x. 4 root root   51 Sep 16 16:06 ..
-rwxr-xr-x  1 root root  120 Sep  6 11:33 Corefile
-rwxr-xr-x  1 root root 1522 Sep 12 11:40 hosts
-rw-r--r--  1 root root  199 Sep  6 11:33 install-coredns.sh
[root@corends coredns]# cat install-coredns.sh 
#!/bin/bash

docker run -d \
  --restart always \
  --name coredns \
  -p 53:53/tcp \
  -p 53:53/udp \
  -v /home/coredns/hosts:/etc/hosts \
  -v /home/coredns/Corefile:/Corefile \
  coredns/coredns
[root@corends coredns]# cat Corefile 
.:53 {
    hosts {
        fallthrough
    }
    forward . 202.96.128.86 114.114.114.114 8.8.8.8
    errors
    cache
}
[root@corends coredns]# cat hosts 
# 根据实际需要修改
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

192.168.0.200 gz.yaohuiw.net
192.168.0.200 boss.yaohuiw.net
192.168.0.200 login.yaohuiw.net
192.168.0.200 pay.yaohuiw.net
192.168.0.200 wx.yaohuiw.net


192.168.0.199 gz.yaohjk.com
192.168.0.199 boss.yaohjk.com
192.168.0.199 login.yaohjk.com
192.168.0.199 pay.yaohjk.com
192.168.0.199 wx.yaohjk.com

192.168.0.198 boss.yaohuiw.xyz
192.168.0.198 gz.yaohuiw.xyz
192.168.0.198 login.yaohuiw.xyz
192.168.0.198 pay.yaohuiw.xyz
192.168.0.198 wx.yaohuiw.xyz
[root@corends coredns]#

验证:

[root@test2 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.0.246



[root@test2 ~]# nslookup devgz.yaohjk.com
Server:        192.168.0.246
Address:    192.168.0.246#53

Name:    devgz.yaohjk.com
Address: 192.168.0.200
** server can't find devgz.yaohjk.com: NXDOMAIN

[root@test2 ~]# nslookup gz.yaohjk.com
Server:        192.168.0.246
Address:    192.168.0.246#53

Name:    gz.yaohjk.com
Address: 192.168.0.199

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!