dns主從服務(wù)器搭建-多域名正向域名解析
dns主從服務(wù)器搭建-多域名正向域名解析
0.機(jī)器規(guī)劃:
主dns: ?192.168.27.128
從dns: ?192.168.27.129
客戶端機(jī)器: 192.168.27.130
測試域名:?test.com ?aaa.com
要求結(jié)果: ?
1).將域名www1.test.com 解析到ip: 192.168.27.100
2).將域名www2.test.com 解析到ip: 192.168.27.200
3).將域名www1.aaa.com 解析到ip: 192.168.27.101
4).將域名www2.aaa.com 解析到ip: 192.168.27.201
1.搭建主dns服務(wù)器(192.168.27.128上)
[root@dns-master ~]# ifconfig |grep 192
????????inet 192.168.27.128 ?netmask 255.255.255.0 ?broadcast 192.168.27.255
[root@dns-master ~]# yum -y install bind bind-chroot
[root@dns-master ~]# vim /etc/named.conf ???????????#修改主配置文件
options {
????????listen-on port 53 { 192.168.27.128; }; ?#監(jiān)聽的ip,ip也可以改成any,用該機(jī)器的任何ip都能連接進(jìn)來
????????listen-on-v6 port 53 { ::1; };
????????directory ??????"/var/named"; ??????????#定義數(shù)據(jù)文件存放路徑
????????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";
????????recursing-file ?"/var/named/data/named.recursing";
????????secroots-file ??"/var/named/data/named.secroots";
????????allow-query ????{ any; }; ??#誰可以查詢DNS,任何一臺(tái)機(jī)器都能使用我們的dns
...
}
[root@dns-master ~]# cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bak
[root@dns-master ~]# vim /etc/named.rfc1912.zones???#修改次配置文件,區(qū)域文件
zone "test.com" IN { ???????????????????????//定義test.com
????????type master; ???????????????????????//服務(wù)器類型為主服務(wù)器
????????file "test.com.zone"; ??????????????//定義數(shù)據(jù)文件名
????????allow-transfer { 192.168.27.129; }; ?//定義從服務(wù)器IP
};
zone "aaa.com" IN { ????????????????????????//定義aaa.com
????????type master; ???????????????????????//服務(wù)器類型為主服務(wù)器 ?
????????file "aaa.com.zone"; ???????????????//定義數(shù)據(jù)文件名 ?
????????allow-transfer { 192.168.27.129; }; ?//定義從服務(wù)器IP
};
[root@dns-master ~]# vim /var/named/test.com.zone ??#定義區(qū)域數(shù)據(jù)文件名,配置域名正向解析
$TTL 1D ???????????????????????????????;設(shè)置有效地址解析記錄的默認(rèn)緩存時(shí)間,1D或3600,3600是秒
@ ??????IN SOA ?@ 144110.qq.com. ( ????;設(shè)置SOA標(biāo)記(起始授權(quán)機(jī)構(gòu)的資源記錄,描述了域名的管理員,電子郵件地址)
?????????????????????????????????0 ????;序列號(hào),修改次序,每次修改值手動(dòng)增加1,最大位數(shù)為11位,當(dāng)salve進(jìn)行數(shù)據(jù)同步時(shí),會(huì)比較這個(gè)號(hào)碼,比salve號(hào)碼大就進(jìn)行更新,否則忽略
?????????????????????????????????3H ???;refresh刷新時(shí)間,告訴salve,要隔多久進(jìn)行數(shù)據(jù)同步 (3h)
?????????????????????????????????15M ??;retry重試時(shí)間,salve更新失敗后,多久后重試 (15min)
?????????????????????????????????1W ???;expire記錄逾越時(shí)間,當(dāng)salve一直未能成功與master取得聯(lián)系,將會(huì)放棄,同時(shí)數(shù)據(jù)也將標(biāo)記為過期(expired),失效時(shí)間:1周
?????????????????????????????????3H ) ?;minimum,最小TTL值,如果沒有定義$TTL,就會(huì)以此值為標(biāo)準(zhǔn)
NS dns.test.com. ???????;權(quán)威dns,dns管理員
dns.test.com. A 192.168.27.128
www1.test.com. A 192.168.27.100
www2.test.com. A 192.168.27.200
[root@dns-master ~]# vim?/var/named/aaa.com.zone ???#定義區(qū)域數(shù)據(jù)文件名,配置域名正向解析
$TTL 1D ???????????????????????????????;設(shè)置有效地址解析記錄的默認(rèn)緩存時(shí)間,1D或3600,3600是秒
@ ??????IN SOA ?@ 144110.qq.com. ( ????;設(shè)置SOA標(biāo)記(起始授權(quán)機(jī)構(gòu)的資源記錄,描述了域名的管理員,電子郵件地址)
?????????????????????????????????0 ????;序列號(hào),修改次序,每次修改值手動(dòng)增加1,最大位數(shù)為11位,當(dāng)salve進(jìn)行數(shù)據(jù)同步時(shí),會(huì)比較這個(gè)號(hào)碼,比salve號(hào)碼大就進(jìn)行更新,否則忽略
?????????????????????????????????3H ???;refresh刷新時(shí)間,告訴salve,要隔多久進(jìn)行數(shù)據(jù)同步 (3h)
?????????????????????????????????15M ??;retry重試時(shí)間,salve更新失敗后,多久后重試 (15min)
?????????????????????????????????1W ???;expire記錄逾越時(shí)間,當(dāng)salve一直未能成功與master取得聯(lián)系,將會(huì)放棄,同時(shí)數(shù)據(jù)也將標(biāo)記為過期(expired),失效時(shí)間:1周
?????????????????????????????????3H ) ?;minimum,最小TTL值,如果沒有定義$TTL,就會(huì)以此值為標(biāo)準(zhǔn)
NS dns.aaa.com. ??;權(quán)威dns,dns管理員
dns.aaa.com. A 192.168.27.128
www1.aaa.com. A 192.168.27.101
www2.aaa.com. A 192.168.27.201
[root@dns-master ~]# systemctl enable named
[root@dns-master ~]# systemctl start named
[root@dns-master ~]# systemctl status named
● named.service - Berkeley Internet Name Domain (DNS)
???Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; vendor preset: disabled)
???Active: active (running) since Mon 2023-03-20 04:16:46 CST; 31s ago
?
2.搭建從dns服務(wù)器(192.168.27.129上) ?主要修改主配置文件和次配置文件,域名解析文件會(huì)從主自動(dòng)同步過來
[root@dns-slave ~]# ifconfig |grep 192
????????inet 192.168.27.129 ?netmask 255.255.255.0 ?broadcast 192.168.27.255
[root@dns-slave ~]# yum -y install bind bind-chroot
[root@dns-slave ~]# vim /etc/named.conf ???????????#修改主配置文件
options {
????????listen-on port 53 { 192.168.27.129; }; ?#監(jiān)聽的ip,ip也可以改成any,用該機(jī)器的任何ip都能連接進(jìn)來
????????listen-on-v6 port 53 { ::1; };
????????directory ??????"/var/named"; ??????????#定義數(shù)據(jù)文件存放路徑
????????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";
????????recursing-file ?"/var/named/data/named.recursing";
????????secroots-file ??"/var/named/data/named.secroots";
????????allow-query ????{ any; }; ??#誰可以查詢DNS,任何一臺(tái)機(jī)器都能使用我們的dns
...
}
[root@dns-slave?~]# cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bak
[root@dns-slave?~]# vim /etc/named.rfc1912.zones???#修改次配置文件,區(qū)域文件
zone "test.com" IN { ?????????????????????//定義test.com
????????type slave; ??????????????????????//服務(wù)器類型為主服務(wù)器
????????file "slaves/test.com.zone"; ?????//定義數(shù)據(jù)文件名,不用手動(dòng)創(chuàng)建,啟動(dòng)服務(wù)后會(huì)自動(dòng)同步主dns的文件
????????masters { 192.168.27.128; }; ?????//指向主dns服務(wù)器IP
};
zone "aaa.com" IN { ???????????????????????//定義aaa.com
????????type slave; ???????????????????????//服務(wù)器類型為主服務(wù)器 ?
????????file "slaves/aaa.com.zone"; ???????//定義數(shù)據(jù)文件名,不用手動(dòng)創(chuàng)建,啟動(dòng)服務(wù)后會(huì)自動(dòng)同步主dns的文件
????????masters { 192.168.27.128; }; ??????//指向主dns服務(wù)器IP
};
[root@dns-slave ~]#?ls /var/named/slaves/???#啟動(dòng)從dns服務(wù)前,查看正向域名解析文件還沒有同步過來
空
[root@dns-slave ~]# systemctl enable named
[root@dns-slave ~]# systemctl start named
[root@dns-slave ~]# systemctl status named
● named.service - Berkeley Internet Name Domain (DNS)
???Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; vendor preset: disabled)
???Active: active (running) since Mon 2023-03-20 04:29:01 CST; 10s ago
[root@dns-slave ~]#?ls /var/named/slaves/???#啟動(dòng)從dns服務(wù)后,查看正向域名解析文件已經(jīng)同步過來
aaa.com.zone ?test.com.zone
3.客戶端測試域名解析
[root@client ~]# ifconfig |grep 192
????????inet 192.168.27.130 ?netmask 255.255.255.0 ?broadcast 192.168.27.255
[root@client ~]# yum -y install bind-utils??????????#安裝nslookup命令
1).測試test.com和aaa.com域名解析(將dns指向主從兩個(gè)dns服務(wù)器)
[root@client ~]#?cat /etc/resolv.conf ????#將dns指向主從兩個(gè)dns服務(wù)器
nameserver 192.168.27.128
nameserver 192.168.27.129
[root@client ~]# nslookup www1.test.com
Server: ?192.168.27.128
Address: 192.168.27.128#53
Name: www1.test.com
Address: 192.168.27.100
[root@client ~]# nslookup www2.test.com
Server: ?192.168.27.128
Address: 192.168.27.128#53
Name: www2.test.com
Address: 192.168.27.200
[root@client ~]# nslookup www1.aaa.com
Server: ?192.168.27.128
Address: 192.168.27.128#53
Name: www1.aaa.com
Address: 192.168.27.101
[root@client ~]# nslookup www2.aaa.com
Server: ?192.168.27.128
Address: 192.168.27.128#53
Name: www2.aaa.com
Address: 192.168.27.201
[root@client ~]#?ping www1.test.com
PING www1.test.com (192.168.27.100) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable
[root@client ~]# ping www2.test.com
PING www2.test.com (192.168.27.200) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable
[root@client ~]# ping www1.aaa.com
PING www1.aaa.com (192.168.27.101) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable
[root@client ~]# ping www2.aaa.com
PING www2.aaa.com (192.168.27.201) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable
2).停止主dns服務(wù),模擬主dns掛掉(192.168.27.128停止主dns服務(wù))
[root@dns-master ~]#?systemctl stop named
[root@dns-master ~]# systemctl status named
● named.service - Berkeley Internet Name Domain (DNS)
???Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; vendor preset: disabled)
???Active: inactive (dead) since Mon 2023-03-20 04:45:28 CST; 7s ago
3).測試test.com和aaa.com域名解析(也是正常的能解析,不過指向的dns服務(wù)器地址改成了從dns)
[root@client ~]#?cat /etc/resolv.conf ????#將dns指向主從兩個(gè)dns服務(wù)器
nameserver 192.168.27.128
nameserver 192.168.27.129
[root@client ~]# nslookup www1.test.com
Server: ?192.168.27.129
Address: 192.168.27.129#53
Name: www1.test.com
Address: 192.168.27.100
[root@client ~]# nslookup www2.test.com
Server: ?192.168.27.129
Address: 192.168.27.129#53
Name: www2.test.com
Address: 192.168.27.200
[root@client ~]# nslookup www1.aaa.com
Server: ?192.168.27.129
Address: 192.168.27.129#53
Name: www1.aaa.com
Address: 192.168.27.101
[root@client ~]# nslookup www2.aaa.com
Server: ?192.168.27.129
Address: 192.168.27.129#53
Name: www2.aaa.com
Address: 192.168.27.201
[root@client ~]#?ping www1.test.com
PING www1.test.com (192.168.27.100) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable
[root@client ~]# ping www2.test.com
PING www2.test.com (192.168.27.200) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable
[root@client ~]# ping www1.aaa.com
PING www1.aaa.com (192.168.27.101) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable
[root@client ~]# ping www2.aaa.com
PING www2.aaa.com (192.168.27.201) 56(84) bytes of data.
From client (192.168.27.130) icmp_seq=1 Destination Host Unreachable
From client (192.168.27.130) icmp_seq=2 Destination Host Unreachable