前提:下载bind服务,查看文件
[root@localhost ~]# yum install bind -y
OS 5.2 kB/s | 1.9 kB 00:00
everything 5.5 kB/s | 1.9 kB 00:00
EPOL 4.9 kB/s | 1.9 kB 00:00
debuginfo 6.7 kB/s | 2.2 kB 00:00
source 6.5 kB/s | 2.2 kB 00:00
update 4.6 kB/s | 1.9 kB 00:00
update-source 4.7 kB/s | 2.2 kB 00:00
Package bind-32:9.16.37-4.oe2309.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost ~]# rpm -ql bind
/etc/named.conf
/var/named/slaves
一、配置正向解析
1、修改主配置文件/etc/named.conf
[root@localhost ~]# vi /etc/named.conf
options {
listen-on port 53 { 192.168.59.134; };
directory "/var/named";
allow-query { any;};
recursion yes;
};
zone "baidu.com" IN {
type master;
file "baidu";
};
2、配置数据配置文件/var/named/baidu
[root@localhost ~]# vi /var/named/baidu
$TTL 1D
@ IN SOA @ admin.admin.com. (
2024011400
1D
1H
3H
1D )
IN NS dns.baidu.com.
dns IN A 192.168.59.134
www IN A 192.168.59.111
ftp IN A 192.168.59.123
a IN A 192.168.59.100
aaa IN CNAME a
3、重启named服务
[root@localhost ~]# systemctl restart named
4、检测
[root@localhost ~]# host www.baidu.com 192.168.59.134
Using domain server:
Name: 192.168.59.134
Address: 192.168.59.134#53
Aliases:
www.baidu.com has address 192.168.59.111
[root@localhost ~]# nslookup www.baidu.com 192.168.59.134
Server: 192.168.59.134
Address: 192.168.59.134#53
Name: www.baidu.com
Address: 192.168.59.111
二、反向解析
1、修改主配置文件/etc/named.conf
[root@localhost ~]# vi /etc/named.conf
options {
listen-on port 53 { 192.168.59.134; };
directory "/var/named";
allow-query { any;};
recursion yes;
};
zone "59.168.192.in-addr.arpa" IN {
type master;
file "192";
};
2、配置数据配置文件/var/named/192
[root@localhost ~]# vi /var/named/192
$TTL 1D
@ IN SOA @ admin.admin.com. (
2024011501
1D
1H
3H
1D )
NS dns.baidu.com.
134 PTR dns.baidu.com.
111 PTR www.baidu.com.
123 PTR ftp.baidu.com.
100 PTR a.baidu.com.
3、重启named服务
[root@localhost ~]# systemctl restart named
4、检测
[root@localhost ~]# nslookup
> server 192.168.59.134
Default server: 192.168.59.134
Address: 192.168.59.134#53
> aaa.baidu.com
Server: 192.168.59.134
Address: 192.168.59.134#53
aaa.baidu.com canonical name = a.baidu.com.
Name: a.baidu.com
Address: 192.168.59.100
三、主从DNS服务器 ----- 完全区域传送:复制整个区域文件
主DNS服务器的配置【主dns服务器的ip地址为192.168.59.134】
1、修改主配置文件/etc/named.conf
[root@localhost ~]# vi /etc/named.conf
options {
listen-on port 53 { 192.168.59.134; };
directory "/var/named";
allow-query { any;};
recursion yes;
allow-transfer{192.168.59.138;};
};
zone "baidu.com" IN {
type master;
file "baidu";
};
zone "59.168.192.in-addr.arpa" IN {
type master;
file "192";
};
2、(1)配置数据配置文件/var/named/baidu
[root@localhost ~]# vi /var/named/baidu
$TTL 1D
@ IN SOA @ admin.admin.com. (
2024011400
1M
1M
3M
1D )
IN NS dns.baidu.com.
dns IN A 192.168.59.134
IN NS ns.baidu.com.
ns IN A 192.168.59.138
www IN A 192.168.59.111
ftp IN A 192.168.59.123
a IN A 192.168.59.100
aaa IN CNAME a
2、(2)配置数据配置文件/var/named/192
[root@localhost ~]# vi /var/named/192
$TTL 1D
@ IN SOA @ admin.admin.com. (
2024011501
1M
1M
3M
1D )
NS dns.baidu.com.
134 PTR dns.baidu.com.
NS ns.baidu.com.
138 PTR ns.baidu.com.
111 PTR www.baidu.com.
123 PTR ftp.baidu.com.
100 PTR a.baidu.com.
3、重启named服务
[root@localhost ~]# systemctl restart named
从DNS服务器的配置【从dns服务器的ip地址为192.168.59.138】
前提:关闭防火墙、selinux、下载bind服务,查看文件
[root@192 ~]# systemctl stop firewalld
[root@192 ~]# setenforce 0
[root@192 ~]# yum install bind -y
1、修改主配置文件/etc/named.conf
[root@192 ~]# vi /etc/named.conf
options {
listen-on port 53 { 192.168.59.138; };
directory "/var/named/slaves";
allow-query { any; };
};
zone "baidu.com" IN {
type slave;
file "named.baidu";
masters{192.168.59.134;};
};
zone "59.168.192.in-addr.arpa" IN {
type slave;
file "named.192";
masters { 192.168.59.134; };
};
2、重启named服务
[root@192 ~]# systemctl restart named
3、检测
[root@192 ~]# host www.baidu.com 192.168.59.138
Using domain server:
Name: 192.168.59.138
Address: 192.168.59.138#53
Aliases:
www.baidu.com has address 192.168.59.111
四、主从DNS服务器 ----- 增量区域传送:仅复制区域里变化的文件
注:修改主服务器的区域配置文件,序号比之前的序号大【注:区域文件里面必须要写从服务器的NS和A记录】
主DNS服务器的配置【主dns服务器的ip地址为192.168.59.134】
[root@localhost ~]# vi /var/named/baidu
$TTL 1D
@ IN SOA @ admin.admin.com. (
2024011401
1M
1M
3M
1D )
IN NS dns.baidu.com.
dns IN A 192.168.59.134
IN NS ns.baidu.com.
ns IN A 192.168.59.138
www IN A 192.168.59.111
ftp IN A 192.168.59.123
a IN A 192.168.59.100
b IN A 192.168.59.132
aaa IN CNAME a
[root@localhost ~]# vi /var/named/192
$TTL 1D
@ IN SOA @ admin.admin.com. (
2024011502
1M
1M
3M
1D )
NS dns.baidu.com.
134 PTR dns.baidu.com.
NS ns.baidu.com.
138 PTR ns.baidu.com.
111 PTR www.baidu.com.
123 PTR ftp.baidu.com.
100 PTR a.baidu.com.
132 PTR b.baidu.com.
[root@localhost ~]# systemctl restart named
检测:
tail -f /var/log/messages