利用bind,配置 linux1 为主 DNS 服务器,linux2 为备用 DNS 服务器,为所有linux主机提供冗余DNS正反向解析服务。正向区域文件均为/var/named/named.skills , 反 向 区 域 文 件 均 为/var/named/named.10。
DNS主服务器配置
[root@linux1 ~]# yum install -y bind* //安装服务
[root@linux1 ~]# vi /etc/named.conf //主配置文件
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
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";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
allow-query { any; }; //修改
[root@linux1 ~]# vi /etc/named.rfc1912.zones //解析区域文件
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "skills.lan" IN { //修改
type master;
file "named.skills";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "220.4.10.in-addr.arpa" IN { //修改
type master;
file "named.10";
allow-update { none; };
};
[root@linux1 ~]# cd /var/named/ //进入指定目录
[root@linux1 named]# cp -p named.localhost named.skills //复制正向解析文件
[root@linux1 named]# cp -p named.loopback named.10 //复制反向解析文件
//利用for循环配置正反向解析文件
[root@linux1 named]# for i in {1..9};do echo "linux$i A 10.4.220.10$i" >> /var/named/named.skills ;done
[root@linux1 named]# for i in {1..9};do echo "10$i PTR linux$i.skills.lan." >> /var/named/named.10 ;done
root@linux1 ~]# vi /var/named/named.skills //配置正向解析文件
$TTL 1D
@ IN SOA @ linux1.skills.lan. ( //修改
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
linux1 A 10.4.220.101 //这些是利用for写入的内容
linux2 A 10.4.220.102
linux3 A 10.4.220.103
linux4 A 10.4.220.104
linux5 A 10.4.220.105
linux6 A 10.4.220.106
linux7 A 10.4.220.107
linux8 A 10.4.220.108
linux9 A 10.4.220.109
[root@linux1 ~]# vi /var/named/named.10 //配置反向解析文件
$TTL 1D
@ IN SOA @ linux1.skills.lan. ( //修改
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
PTR localhost.
101 PTR linux1.skills.lan. //这个.一定不能少
102 PTR linux2.skills.lan.
103 PTR linux3.skills.lan.
104 PTR linux4.skills.lan.
105 PTR linux5.skills.lan.
106 PTR linux6.skills.lan.
107 PTR linux7.skills.lan.
108 PTR linux8.skills.lan.
109 PTR linux9.skills.lan.
[root@linux1 named]# firewall-cmd --zone=public --add-port=53/udp --add-port=53/tcp //放行端口
[root@linux1 named]# firewall-cmd --reload //刷新防火墙规则
[root@linux1 named]# systemctl enable --now named //设置开机自启动并且立即启动
备DNS配置
[root@linux2 ~]# vi /etc/named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
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";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
allow-query { any; }; //修改
[root@linux2 ~]# vi /etc/named.rfc1912.zones //解析区域文件
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "skills.lan" IN { //修改
type slave;
file "slaves/named.skills";
masters { 10.4.220.101; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "220.4.10.in-addr.arpa" IN { //修改
type slave;
file "slaves/named.10";
masters { 10.4.220.101; };
};
[root@linux2 ~]# firewall-cmd --zone=public --add-port=53/udp --add-port=53/tcp //放行端口
[root@linux2 ~]# firewall-cmd --reload //刷新防火墙规则
[root@linux2 ~]# systemctl enable --now named.service //开机自启