構建域名服務器DNS
1、概述
1、概念
DNS Domain Name System 域名解析系統
2、原理
一次遞歸屢次迭代
3、DNS做用
正向解析:將域名轉換成對應的IP地址
反向解析:將IP地址轉換成對應的域名
4、使用端口 53 domain TCP UDP查詢
若是查詢時以UDP沒有查詢到完整的信息時,就會再次以TCP協議來從新查詢
主DNS於從DNS同步時使用TCP協議
實驗配置
1、 實驗環境
主DNS: 主機名 master.daren.com IP地址192.168.0.1
從DNS: 主機名 slave.daren.com IP地址 192.168.0.2
緩存DNS: 主機名cache.daren.com IP地址 192.168.0.3
WEB服務器: 主機名 www.daren.com IP地址 192.168.0.10
PC IP地址爲192.168.0.5
主DNS的配置
1、環境的設置
[root@master ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=master.daren.com
[root@master ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.0.1
NETMASK=255.255.255.0
ONBOOT=yes
HWADDR=00:0c:29:52:bc:e0
|
2、安裝軟件包
[root@master ~]# yum -y install bind*
[root@master ~]# yum -y install caching*
|
3、修改主配置文件
[root@master etc]# cd /var/named/chroot/etc/
[root@master etc]# cp named.caching-nameserver.conf named.conf
[root@master etc]# vim named.conf
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
allow-query-cache { any; };
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view any_resolver {
match-clients { any; };
match-destinations { any; };
recursion yes;
include "/etc/named.zone ";
};
|
4、區域配置文件
[root@master etc]# cp -a named.rfc1912.zones named.zone
[root@master etc]# vim named.zone
27 zone "daren.com" IN {
28 type master;
29 file "daren.zone";
30 allow-update { none; };
31 };
32
33 zone "0.168.192.in-addr.arpa" IN {
34 type master;
35 file "daren.addr";
36 allow-update { none; };
37 };
|
5、修改區域數據庫文件:正向解析
[root@master ~]# cd /var/named/chroot/var/named/
[root@master named]# cp -a named.local daren.zone
[root@master named]# vim daren.zone
$TTL 86400
@ IN SOA daren.com. root.daren.com. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS master.daren.com.
master IN A 192.168.0.1
www IN A 192.168.0.10
mail IN A 192.168.0.20
|
反向解析
[root@master named]# cp -a daren.zone daren.addr
[root@master named]# vim daren.addr
$TTL 86400
@ IN SOA daren.com. root.daren.com. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS master.daren.com.
1 IN PTR master.daren.com.
10 IN PRR www.daren.com.
|
6、重啓named服務
[root@master named]# service named restart
從DNS的配置
一、 修改主配置文件
[root@slave etc]# vim named.conf
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
allow-query-cache { any; };
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view any_resolver {
match-clients { any; };
match-destinations { any; };
recursion yes;
include "/etc/named.zone";
"named.conf" 41L, 1179C
|
二、 修改區域配置文件
[root@slave etc]# vim named.zone
27 zone "daren.com" IN {
28 type slave;
29 file "slaves/daren.zone";
30 masters { 192.168.0.1; };
31 };
39 zone "0.168.192.in-addr.arpa" IN {
40 type slave;
41 file "slaves/daren.addr";
42 masters { 192.168.0.1; };
43 ;
|
3、重啓named服務
[root@slave etc]# service named restar
4、查看同步過來的文件
[root@slave named]# cd slaves/
[root@slave slaves]# ls
daren.addr daren.zone
|
緩存DNS的配置
一、 修改主配置文件
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
forwarders { 192.168.0.1; };
allow-query { any; };
allow-query-cache { any; };
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view any_resolver {
match-clients { any; };
match-destinations { any; };
recursion yes;
include "/etc/named.rfc1912.zones";
"named.conf" 41L, 1219C
|
2、重啓named服務
[root@slave etc]# service named restart
客戶端的測試
一、 主DNS的測試
將客戶端的DNS指向主DNS的IP 192.168.0.1
進入cmd依次執行
Nslookup master.daren.com
Nslookup www.daren.com
Nslookup mail.daren.com
看可否解析到正確的地址
二、 從DNS的測試
將客戶端的DNS指向從DNS的IP 192.168.0.2
進入cmd執行
Nslookup www.daren.com
看可否解析到正確的地址
三、 緩存DNS的測試
將客戶端的DNS指向緩存DNS的IP 192.168.0.3
進入cmd依次執行
Nslookup www.daren.com
看可否解析到正確的地址
vim /var/named/chroot/etc/named.conf
//forwarders { 192.168.0.1; }; (將轉發去掉)
將客戶端的緩存清一下
Ipconfig /flushdns
再次執行
Nslookup www.daren.com
看可否解析到正確的地址