1,安装DNS服务器
yum install -y bind
[root@localhost /]# vim /etc/named.conf //修改DNS主配置文件
listen-on port 53 { any; };
allow-query { any; }; //修改这两行的内容
2,修改子配置文件
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone “test.com” IN {
type master;
file “test.com.zone”;
};
zone “100.168.192.in-addr.arpa” {
type master;
file “100.168.192.zone”;
}; ##在内容最后添加一个正向和一个反向解析区域
[root@localhost /]# cd /var/named/ ###进入DNS服务器区域配置文件目录
[root@localhost named]# cp -p named.localhost test.com.zone
[root@localhost named]#cp -p named.loopback 100.168.192.zone ###复制模板区域配置文件为指定区域配置文件。注:一定要保留源文件权限,如果未保留,须将属组改为named。
[root@localhost named]# vim test.com.zone ####编辑正向区域配置文件,修改并添加以下行
$TTL 1D
@ IN SOA dns.test.com root.test.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.test.com.
dns IN A 192.168.100.200 ##这个必须写的
www IN A 192.168.100.200
[root@localhost named]# vim 100.168.192.zone ###编辑反向区域配置文件,修改并添加以下
$TTL 1D
@ IN SOA dns.test.com. root.test.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.test.com.
dns A 192.168.100.200
200 IN PTR www.test.com.
200 IN PTR www.test.com.
3,启动DNS域名解析服务器
[root@localhost named]# systemctl start named
安装nslookup命令测试dns能否解析成功
[root@localhost named]#yum install -y bind-utils
[root@localhost named]#vim /etc/resolv.conf ###给本机的DNS指向自己的dns服务
nameserver 192.168.100.200
4,显示如下则表示成功 此为正向解析
[root@localhost named]# nslookup www.test.com
Server: 192.168.100.200
Address: 192.168.100.200#53
Name: www.test.com
Address: 192.168.100.200
地址,显示如下则表示成功 此为反向解析
[root@localhost named]# nslookup 192.168.100.200
200.100.168.192.in-addr.arpa name = www.test.com.