一、配置bind9服务器之前,先了解这些知识点:
1、DNS解析过程详解:http://www.cnblogs.com/liyuanhong/articles/7353974.html
2、常用域名记录解释(A记录,CNAME,NS记录,MX记录):http://www.cnblogs.com/liyuanhong/articles/7355153.html
3、bind9简介:http://www.cnblogs.com/liyuanhong/articles/7400651.html
4、bind9基本配置讲解:http://www.cnblogs.com/liyuanhong/articles/7400854.html
二、开始在ubuntu上配置bind9作为局域网的域名服务器
1、bind9的安装,这里假设bind9通过apt-get已经装上
2、进入/etc/bind目录下面
3、创建一个区域记录文件(类似这样db.xxx的文件):这里我创建了db.testlyhh.com
4、编辑named.conf.default-zones文件,添加如下:
zone "testlyhh.com" { type master; file "/etc/bind/db.testlyhh.com"; #指明区域记录文件的位置 };5、编辑我们的区域记录文件db.testlyhh.com,如下:
【在此之前,先普及一个小知识: 域名www.baidu.com完整的域名应该是这样的,www.baidu.com. 最后又一个小点,代表根域名:
baidu.com.代表的是域
www其实是baidu.com.域内的一台主机,名字叫www
所以一下的配置aaa、bbb、ccc其实都是一台主机;我们指定了ccc主机的别名又叫bbb
具体参见上面的:DNS解析过程详解
】
$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目录内容:
7、接下来看看DNS配置是否生效,首先在ubuntu本机上指明我们的bind9服务器地址:
需要编辑:/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
接下来ping aaa.testlyhh.com:
到此域名配置成功。
原文链接:https://www.f2er.com/ubuntu/351540.html