场景:
业务系统使用的泛域名模式,并且会随机产生泛域名,所以现在需要使用CoreDns搭建一个新的域名解析服务提供给这个业务系统使用。
CoreDNS下载地址:
安装步骤:
1.解压缩安装包:使用以下命令解压缩下载的安装包。
tar -xzvf coredns_1.11.0_linux_amd64.tgz
2.入解压后的目录:使用以下命令进入解压后的目录。
cd coredns_1.11.0_linux_amd64
3.将CoreDNS二进制文件复制到
/usr/local/bin,添加执行权限。
cp coredns /usr/local/bin/ chmod +x /usr/local/bin/coredns
设置systemctl启动脚本:
创建一个名为
coredns.service
的文件。vim /etc/systemd/system/coredns.service [Unit] Description=CoreDNS DNS server Documentation=https://coredns.io After=network.target [Service] ExecStart=/usr/local/bin/coredns -conf /etc/coredns/Corefile Restart=on-failure [Install] WantedBy=multi-user.target
设置CoreDns配置文件:
创建一个Corefile的文件在/etc/coredns/
. { forward . 8.8.8.8 #除了下面的泛域名都交给这个IP的DNS服务器解析。 } brother.com:53 { errors template ANY AAAA { rcode NXDOMAIN } template IN A *.brother.com { match .*.brother.com answer "{{ .Name }} 60 IN A 192.168.1.99" #访问这个泛域名全部返回99 fallthrough } cache 30 file /etc/coredns/brother.com.zone #A记录配置文件 }
设置CoreDns解析文件:
创建/etc/coredns/brother.com.zone
vim /etc/coredns/brother.com.zone $TTL 3600 @ IN SOA ns1.example.com. admin.example.com. ( 2023081401 ; Serial 3600 ; Refresh 1800 ; Retry 604800 ; Expire 86400 ) ; Minimum TTL IN NS ns1.example.com. *.brother.com. IN A 192.168.1.99
启动并验证:
1.在DNS服务器启动服务:
systemctl start coredns
2.在客户机器上配置dns服务器地址:
vim /etc/resolv.conf nameserver 192.168.1.99
3.在客户机器上使用随机域名验证:
dig d32rd23r2r2.brother.com #或者 nslookup dwewe12e32r3.brother.com #域名随机输入
结果:
![]()