docker部署内网dns解析服务(coredns方案)

目录结构:

[root@harbor coredns]# tree
.
├── Corefile
├── hosts
└── install-coredns.sh
cat install-coredns.sh 
#!/bin/bash

docker run -d \
  --restart always \
  --name coredns \
  -p 53:53/tcp \
  -p 53:53/udp \
  -v /data/service/coredns/hosts:/etc/hosts \
  -v /data/service/coredns/Corefile:/Corefile \
  coredns/coredns
cat Corefile 
.:53 {
    hosts {
        fallthrough
    }
    forward .  114.114.114.114 8.8.8.8
    errors
    cache
}

cat hosts

cat hosts 
192.168.1.97 shanbin.xxx.cn
192.168.1.97 shanbin.xxx.com

验证:

配置域名解析服务器地址:

cat /etc/resolv.conf

# Generated by NetworkManager
#nameserver 114.114.114.114
nameserver 192.168.1.227
[root@harbor coredns]# nslookup  shanbin.xxx.cn
Server:         192.168.1.227
Address:        192.168.1.227#53

Name:   shanbin.xxx.cn
Address: 192.168.1.97

[root@harbor coredns]# ping shanbin.andnext.cn
PING shanbin.andnext.cn (192.168.1.97) 56(84) bytes of data.
64 bytes from shanbin.xxx.cn (192.168.1.97): icmp_seq=1 ttl=63 time=0.218 ms
64 bytes from shanbin.xxx.cn (192.168.1.97): icmp_seq=2 ttl=63 time=0.251 ms
64 bytes from shanbin.xxx.cn (192.168.1.97): icmp_seq=3 ttl=63 time=0.257 ms
64 bytes from shanbin.xxx.cn (192.168.1.97): icmp_seq=4 ttl=63 time=0.565 ms
^C
--- shanbin.andnext.cn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 0.218/0.322/0.565/0.142 ms

你可能感兴趣的:(docker,容器,运维)