rhce-爱代码爱编程
配置dns主从服务器
#环境准备
[root@server ~]# systemctl stop firewalld
[root@server ~]# setenforce 0
#安装软件
[root@server ~]# yum install bind -y
/etc/named.conf # bind主配置文件
/var/named/slaves # 从dns服务器文件夹
#主服务器配置
(ip:192.168.129.135)
[root@server ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.129.135; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
allow-query { any; };
allow-transfer { 192.168.129.134; }; #允许对该IP的客户机进行传输
#配置正向解析域
zone "baidu.com" IN {
type master;
file "named.baidu.com";
};
#配置反向解析域
zone "129.168.192.in-addr.arpa" IN {
type master;
file "named.192.168.129.131";
};
#正向区域文件
[root@server ~]# vim /var/named/named.baidu.com
$TTL 1D
@ IN SOA @ admin.admin.com (2024011400
1M
1M
1M
3M)
IN NS dns.baidu.com.
dns IN A 192.168.129.135
www IN A 192.168.129.111
ftp IN A 192.168.129.123
a IN A 192.168.129.100
aaa IN CNAME a
#反向区域文件
[root@server ~]# vim /var/named/named.192.168.129.131
$TTL 1D
@ IN SOA @ admin.admin.com. (2024011501
1D
1H
1W
3H)
NS dns.baidu.com.
135 IN PTR dns.baidu.com.
134 IN PTR ns.baidu.com.
111 IN PTR www.baidu.com.
100 IN PTR a.baidu.com.
#重启软件
[root@server ~]# systemctl restart named
从服务器配置
#环境准备
#关闭防火墙
#安装软件包
[root@client ~]# yum install bind -y
[root@client ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.129.135; };
listen-on-v6 port 53 { ::1; };
directory "/var/named/";
zone "baidu.com" IN {
type slave;
file "named.baidu.com";
masters {192.168.129.135; };
};
zone "129.168.192,in -addr.arpa" IN {
type slave;
file "named.192.168.129.131";
masters { 192.168.129.135 ;};
};
[root@client ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.129.135 #设置DNS服务器的IP地址
[root@client ~]# systemctl restart named
#测试
[root@client ~]# host www.baidu.com
www.baidu.com has address 192.168.129.111
[root@client ~]# host 192.168.129.135
135.129.168.192.in-addr.arpa domain name pointer dns.baidu.com.