zone "testlyhh.com" { type master; file "/etc/bind/db.testlyhh.com"; #指明区域记录文件的位置 };5、编辑我们的区域记录文件db.testlyhh.com,如下: @H_403_0@【在此之前,先普及一个小知识: 域名www.baidu.com完整的域名应该是这样的,www.baidu.com. 最后又一个小点,代表根域名: @H_403_0@ baidu.com.代表的是域 @H_403_0@ www其实是baidu.com.域内的一台主机,名字叫www @H_403_0@ 所以一下的配置aaa、bbb、ccc其实都是一台主机;我们指定了ccc主机的别名又叫bbb @H_403_0@ 具体参见上面的:DNS解析过程详解 @H_403_0@】
$TTL 604800 @ IN SOA testlyhh.com. root.localhost. ( 1 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS localhost. testlyhh.com IN NS 192.168.1.108 aaa IN A 192.168.1.108 bbb IN A 192.168.1.108 ccc IN CNAME bbb6.编辑named.conf.options文件,为局域网其他机器提供dns服务(修改option的listen-on语句):
//acl "trusted" { // 127.0.0.1; # ns1 - can be set to localhost // 192.168.1.108; # ns2 //}; options { directory "/var/cache/bind"; //recursion yes; # 启用递归寻址 //allow-recursion { trusted; }; # 允许“trusted”列表前来递归寻址 listen-on port 53 {127.0.0.1;192.168.1.108; }; # 此处填写ns1的内网IP地址。仅在内网监听 allow-transfer { none; }; # 默认禁用zone transfer // If there is a firewall between you and nameservers you want // to talk to,you may need to fix the firewall to allow multiple // ports to talk. See http://www.kb.cert.org/vuls/id/800113 // If your ISP provided one or more IP addresses for stable // nameservers,you probably want to use them as forwarders. // Uncomment the following block,and insert the addresses replacing // the all-0's placeholder. // forwarders { // 0.0.0.0; // }; //======================================================================== // If BIND logs error messages about the root key being expired,// you will need to update your keys. See https://www.isc.org/bind-keys //======================================================================== dnssec-validation auto; auth-nxdomain no; # conform to RFC1035 listen-on-v6 { any; }; };配置完成,重启服务:
service bind9 restart展示一下我的/etc/bind目录内容: @H_403_0@
@H_403_0@7、接下来看看DNS配置是否生效,首先在ubuntu本机上指明我们的bind9服务器地址: @H_403_0@需要编辑:/etc/resolv.conf文件,在nameserver的开头之前加入一行,指明域名:
# 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 192.168.1.108 #nameserver 127.0.1.1 search DHCP HOST@H_403_0@接下来ping aaa.testlyhh.com: @H_403_0@
@H_403_0@到此域名配置成功。 @H_403_0@三、配置局域网自动获取配置好的DNS服务器地址: @H_403_0@如果现在局域网内自动给电脑分配我们配置的DNS服务器,则只需在搭建DHCP分配IP时把DNS自动指定成配好的DNS即可