服务器IP:172.18.1.12
apt install bind9 -y
进入/etc/bind目录下,打开named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
// 添加一下内容
// mytest.io 需要解析的根域名
// file     需要配置解析文件的名称
zone "mytest.io" {
        type master;
file "db.mytest.io";
};
cp /etc/bind/db.local /var/cache/bind/db.mytest.io
cd /var/cache/bind/
cat db.mytest.io 
; BIND data file for local loopback interface
$TTL    604800
@       IN      SOA      dns.mytest.io. root.mytest.io. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
@       IN      NS      dns.mytest.io.
dns     IN      A       172.18.1.12
rancher IN      A       172.18.1.12
rancher IN      A       172.18.1.13
打开/etc/bind/name.conf.options中添加上forwarders,可以实现外网转发
forwarders {
     8.8.8.8;
};
systemctl start bind9
systemctl enable bind9
打开/etc/resolvconf/resolv.conf.d/head文件将dns的IP地址写入,写入head的原因是如果在一些公有云环境下/etc/resolv.conf里面的内容会在机器重启后被覆盖,但是写入head就可以默认写入resolv.conf,并且默认在第一行,优先被解析。
cat /etc/resolvconf/resolv.conf.d/head 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 172.18.1.12
nslookup rancher.mytest.io
Server:         172.18.1.12
Address:        172.18.1.12#53
Name:   rancher.mytest.io
Address: 172.18.1.13
Name:   rancher.mytest.io
Address: 172.18.1.12原文:https://blog.51cto.com/wangpengtai/2418569