31人参与 • 2025-02-14 • 云虚拟主机
在系统应用中,经常会遇到需要使用 https 域名通讯的需要,在内网中,我们不需要正式在互联网上注册域名,自建一个 dns 服务就能很好的解决问题。
本文内网为使用 docker 运行一个 coredns 服务的代码示例:
version: '3.7' services: coredns: image: coredns/coredns:1.10.0 container_name: coredns ports: - 53:53/udp volumes: - ./coredns/corefile:/corefile
.:53 { hosts { 192.168.1.11 test.com 192.168.1.12 test1.com fallthrough } forward . 8.8.8.8:53 114.114.114.114:53 log }
其中 forward 指向上级 dns 服务
我们还可以将 hosts 独立出来为一个单独的文件,
.:53 { hosts /etc/coredns/hostsfile { fallthrough } forward . 8.8.8.8:53 114.114.114.114:53 log }
其中 /etc/coredns/hostsfile 为内部域名解析映射文件,
version: '3.7' services: coredns: image: coredns/coredns:1.10.0 container_name: coredns ports: - 53:53/udp volumes: - ./coredns/hostsfile:/etc/coredns/hostsfile - ./coredns/corefile:/corefile
192.168.1.11 test.com 192.168.1.12 test1.com
以 linux 为例,修改配置文件 cat /etc/resolv.conf 设置 nameserver 为运行的这个 dns 服务ip地址即可,
[root@localhost /]# cat /etc/resolv.conf # generated by networkmanager nameserver 192.168.1.2
保持后就可以使用 nslookup 或者 ping 来验证内部域名解析是否正常了。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论