操作系统: Ubuntu 16.04
服务器 IP:172.18.1.12
1. 安装 bind9
apt install bind9 -y
2. 配置解析文件
进入 / 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";
- };
3. 配置域解析文件
cp /etc/bind/db.local /var/cache/bind/db.mytest.io
4. 配置域解析文件
- 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
5. 设置外网转发
打开 / etc/bind/name.conf.options 中添加上 forwarders, 可以实现外网转发
- forwarders {
- 8.8.8.8;
- };
6. 启动 bind 服务器
- systemctl start bind9
- systemctl enable bind9
7. 配置 dns 解析
打开 / 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
8. 测试 dns
- 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
来源: http://www.bubuko.com/infodetail-3119036.html