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

本文展示了如何在Linux环境下使用CoreDNS作为本地DNS服务器,并通过`install-coredns.sh`脚本进行配置。Corefile配置文件指定了使用114.114.114.114和8.8.8.8作为转发DNS,并添加了自定义hosts条目。验证过程显示,解析请求成功返回了192.168.1.97的IP地址。
摘要由CSDN通过智能技术生成

目录结构:

[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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

均衡教派.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值