前言
DNS服务工作原理
当用户使用主机 发送/接收 邮件,或浏览网页时,就是由主机上配置的DNS服务器地址负责将域名转换成对应的IP地址。
递归查询
是指DNS服务器在收到用户发起的请求时,必须向用户返回一个准确的查询结果。如果DNS服务器本地没有存储与之对应的信息,则该服务器需要询问其他服务器,并将返回的查询结果提交给用户。
一般客户机和本地DNS服务器之间属于递归查询,即当客户机向DNS服务器发出请求后,若DNS服务器本身不能解析,则会向另外的DNS服务器发出查询请求,得到最终的肯定或否定的结果后转交给客户机。
此查询的源和目标保持不变,为了查询结果只需要发起一次查询。
递归算法:客户端向LocalDNS发起域名查询-->localDNS不知道域名对应的IP-->但它知道谁知道->他代为帮客户端去查找-->最后再返回最终结果。
迭代查询
是指DNS服务器在收到用户发起的请求时,并不直接回复查询结果,而是告诉另一台DNS服务器的地址,用户再向这台DNS服务器提交请求,这样依次反复,直到返回查询结果。一般情况下(有例外)本地的DNS服务器向其它DNS服务器的查询属于迭代查询,如:若对方不能返回权
威的结果,则它会向下一个DNS服务器(参考前一个DNS服务器返回的结果)再次发起进行查询,直到返回查询的结果为止。此查询的源不变,但查询的目标不断变化,为查询结果一般需要发起多次查询。
迭代算法:客户端向LocalDNS发起域名查询-->localDNS不知道域名对应的IP-->但它知道谁知道并推荐客户端应该找谁-->客户端自己去找它。
DNS缓存
DNS缓存是将解析数据存储在靠近发起请求的客户端的位置,也可以说DNS数据是可以缓存在任意位置,最终目的是以此减少递归查询过程,可以更快的让用户获得请求结果
VMware NAT环境
1、安装DNS服务器
#selinux、firewalld实际视情况而进行修改,这里测试、练习统一进行修改
#网卡名称统一,这里练习就不做了
#修改主机名称
[root@c7-dns-10 ~]# hostnamectl set-hostname c7-dns-10
#配置文件开启selinux警告模式
[root@c7-dns-10 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#Disabled :不启用控制系统。
#permissive:开启控制系统,但是处于警告模式。即使你违反了策略的话它让你继续操作,但是把你的违反的内容记录下来。
#Enforcing:开启控制系统,处于强制状态。一旦违反了策略,就无法继续操作下去。
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
#动态开启selinux警告
[root@c7-dns-10 ~]# setenforce 0
#测试环境随便关,生产环境不行,firewalld有图形化界面,也可以用iptables
#开机不启动防火墙并关闭防火墙
[root@c7-dns-10 ~]# systemctl disable --now firewalld
#固定IP
[root@c7-dns-10 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="none"
IPADDR=172.29.7.10
PREFIX=24
GATEWAY=172.29.7.254
DNS1=114.114.114.114
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
#重启网卡
[root@c7-dns-10 ~]# nmcli connection reload
[root@c7-dns-10 ~]# nmcli connection up ens33
#修改时区
[root@c7-dns-10 ~]# timedatectl set-timezone Asia/Shanghai
#配置时间同步
[root@c7-dns-10 ~]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
##禁用0,1,2,3 添加阿里云一行
server ntp1.aliyun.com iburst
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
#重启时间同步程序并设为开机自启
[root@c7-dns-10 ~]# systemctl restart chronyd
[root@c7-dns-10 ~]# systemctl enable --now chronyd
#查看时间是否同步
[root@c7-dns-10 ~]# chronyc -n sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? 120.25.115.20 2 6 1 9 -1253us[-1253us] +/- 28ms
#安装dns服务器 bind:dns服务器 bind-utils:dns工具包
[root@c7-dns-10 ~]# yum -y install bind bind-utils
dns域名解析配置,先体验一下,相关的解释在下文
这里主要配置了三个文件
named.conf:主配置文件
named.rfc1912.zones:中间配置文件
db.glusterfs.com(centos7中没有范本需要自己写):具体解析文件
#配置过程(非安装,属于个人配置,下面有相应的模块解释)
#在named.rfc1912.zones中间配置文件添加需要解析的域名
[root@c7-dns-10 ~]# tail -n 5 /etc/named.rfc1912.zones
zone "glusterfs.com" IN {
type master;
file "/etc/named/db.glusterfs.com";
};
#写具体解析文件 路径由上面的中间配置文件里的file指定
[root@c7-dns-10 ~]# cat /etc/named/db.glusterfs.com
glusterfs.com. 86400 IN SOA glusterfs-dns. admin.gluster.com. ( 123 3H 15M 1D 1W )
glusterfs.com. 86400 IN NS dns1.glusterfs.com.
dns1.glusterfs.com. 86400 IN A 172.29.7.10
node1.glusterfs.com. 86400 IN A 172.29.7.21
node2.glusterfs.com. 86400 IN A 172.29.7.22
node3.glusterfs.com. 86400 IN A 172.29.7.23
node4.glusterfs.com. 86400 IN A 172.29.7.24
#修改属主属组和权限
[root@c7-dns-10 ~]# chmod 644 /etc/named/db.glusterfs.com
[root@c7-dns-10 ~]# chown root:root /etc/named/db.glusterfs.com
#开机自启dns服务器
[root@c7-dns-10 ~]# systemctl enable --now named.service
#修改主配置文件,使其可以解析到主机
[root@c7-dns-10 ~]# vim /etc/named.conf
options {
##禁用这三个选项
##此配置表示DNS服务只监听了本机127.0.0.1的53端口,如果对外提供DNS服务,可以将此行注释或值改成any
#listen-on port 53 { 127.0.0.1; };
##监听IPV6的53端口,配置方法同上
#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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
##此配置表示仅本机可以使用DNS服务的解析查询功能,如果对外提供DNS服务,可以将此行注释或值改成any
#allow-query { localhost; };
#测试
[root@c7-dns-10 ~]# host node1.glusterfs.com 172.29.7.10
Using domain server:
Name: 172.29.7.10
Address: 172.29.7.10#53
Aliases:
node1.glusterfs.com has address 172.29.7.21
2、dns配置文件
[root@c7-dns-10 ~]# rpm -ql bind
/etc/logrotate.d/named
/etc/named
/etc/named.conf #主配置文件
/etc/named.iscdlv.key
/etc/named.rfc1912.zones #中间配置文件,该文件中定义了域名和具体解析规则文件的对应关系
/etc/named.root.key
/etc/rndc.conf
/etc/rndc.key
/etc/rwtab.d/named
/etc/sysconfig/named
......
#一般情况下,最重要的有三个文件 主配置文件、中间配置文件、具体解析文件
1.主配置文件
全局配置 options{}; 全局配置选项
日志子系统配置 logging{}; 运行日志
网络自定义集合 acl 将某个网段或某个具体IP地址定义在一个集合里面
视图 view 配合acl将不同的请求来源用不同的解析规则返回,实现智能DNS
[root@c7-dns-10 ~]# cat /etc/named.conf
options {
#此配置表示DNS服务只监听了本机127.0.0.1的53端口,如果对外提供DNS服务,可以将此行注释或值改成any
listen-on port 53 { 127.0.0.1; };
#监听IPV6的53端口,配置方法同上
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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
#此配置表示仅本机可以使用DNS服务的解析查询功能,如果对外提供DNS服务,可以将此行注释或值改成any
allow-query { localhost; };
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
#如果是yes,并且一个DNS询问要求递归,那么服务器将会做所有能够回答查询请求的工作。如果recursion是off的,并且服务器不知道答案,它将会返回一个推荐(referral)响应。
recursion yes;
#DNS安全扩展,是由IETF提供的一系列DNS安全认证的机制(可参考RFC2535)。它提供了一种来源鉴定和数据完整性的扩展,但不去保障可用性、加密性和证实域名不存在。DNSSEC是为解决DNS欺骗和缓存污染而设计的一种安全机制。
dnssec-enable yes;
dnssec-validation yes;
/* Path to ISC DLV key */
#ISC DLV密钥的路径
bindkeys-file "/etc/named.root.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
};
#日志模块
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
#解析域名一般在中间配置文件中写
zone "." IN {
type hint;
file "named.ca";
};
#中间配置文件named.rfc1912.zones
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
2、中间配置文件
zone "ZONE_NAME" IN { #IN 可以省略不写
type {master|slave|hint|forward}; #类型 master,slave 用于DNS主从,forward表示转发
file "file_path"; #具体解析规则文件路径
allow-update { none; }; #在master zone的 zone statement 内设置,指定了允许哪些主机提交该zone的动态DNS更新。默认是拒绝来自所有主机的更新。
};
[root@c7-dns-10 ~]# cat /etc/named.rfc1912.zones
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
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 "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
#上面的都不需要修改,在后面追加我们需要的域名就行
#解析glusterfs.com域名下的所有网站
#例如www.glusterfs.com、test.glusterfs.com.......
zone "glusterfs.com" IN {
type master;
file "/etc/named/db.glusterfs.com";
};
1.关于网址、域名
www.glusterfs.com
www 是主机名
glusterfs 是二级域名
com 是一级域名
. 是顶级域名,默认不显示
所以这个网址的全称是www.glusterfs.com.最后需要追加一个点,但是现在默认情况下就会给你补最后的一个.
2.allow 访问控制指令
#在named配置中有四个allow开头的字段,主要用来实现访问控制
allow-query{}; 允许查询本DNS的主机,白名单,注释就代表所有主机都可使用本机当DNS
allow-transfer{}; 允许区域传送的主机,白名单,注释代表所有,一般用在主从DNS配置时指定从节点
allow-recursion{}; 允许递归的主机,建议全局使用
allow-update{}; 允许可以远程更新解析规则的主机
3.acl地址集合
#ACL:将一个或多个网段(或具体IP地址)定义在一个集合里面,并通过统一的名称进行调用。
#ACL 只能先定义后调用,因此一般放在配置文件的最上面,在 options 之前定义。
none 排除所有主机
any 所有主机
localhost 本机
localnet 本机IP同子网掩码运算后得到的网段
#acl格式
acl ACL_NAME{
IP;
IP;
NET/NETMAST;
NET/NETMAST;
......
};
#例子
acl test_net{
192.168.0.0/24;
172.16.0.0/24;
};
acl prod_net{
10.0.0.0/24;
};
acl other_net{
any;
};
4.view 视图
#view:视图,将ACL和具体的解析规则对应起来,实现根据条件解析,实现智能DNS
#每个view用来匹配一个ACL;
#一个bind服务可以可以定义多个view,每个view 中可定义的一个或多个zone;
#不同的view中可以对同一个域名进行解析,返回不同的解析结果;
#如果定义了view,则所有的zone规则都要写在view中了,不能再直接写在 /etc/named.conf 中了;
#客户端请求到达时,是自上而下检查每个view所对应的ACL的,也就是说,如果请求被命中了,就
#进入解析,不再向后匹配;
#view格式
view VIEW_NAME{
match-clients { acl_name; };
zone "domain" IN {
type mater;
file "domain.zone";
};
include "/etc/named.rfc1912.zones.domain"
};
#例子
view prod_view{
match-clients { prod_net; };
include "/etc/named.rfc1912.zones";
include "/etc/named.rfc1912.zones.prod";
};
view other_view{
match-clients {other_net;};
include "/etc/named.rfc1912.zones";
};
3、具体解析文件
#中间配置文件添加到内容
zone "glusterfs.com" IN {
type master;
file "/etc/named/db.glusterfs.com"; #这个文件路径就是具体解析文件,路径在哪里都可以
};
文件的字段格式
NAME TTL CLASS TYPE VALUE
#字段说明
NAME #资源记录名称,根据TYPE不一样,写法会有不同
TTL #缓存有效期,默认单位是秒,也可以加单位{ M(分), H(时), D(天), W(周) }
CLASS #资源记录类别
TYPE #记录类型
VALUE #此记录对应的具体值,根据TYPE不一样,写法会有不同
文件的两种实现格式
1.省略写法
$TTL 604800
@ IN SOA localhost. root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
@ IN A 127.0.0.1
@ IN AAAA ::1
---------------------------------------------------------------------------------------------
#详细解释一下
#第一行
@ IN SOA localhost. root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
#空行
;
#第二行
@ IN NS localhost.
#第三行
@ IN A 127.0.0.1
#第四行
@ IN AAAA ::1
-------------------------------------------------------------------------------------------------
#第一列 @ 代表zone "glusterfs.com" IN{} 中的glusterfs.com 对于上面五列的NAME
#第二列 写成全局配置TLL 就是文件首行的 $TTL 604800
#非全局写法应该是
@ 604800 IN SOA localhost. root.localhost. ( 2 604800 86400 2419200 604800 )
@ 604800 IN NS localhost.
@ 604800 IN A 127.0.0.1
@ 604800 IN AAAA ::1
#第三列 IN 就是CLASS资源记录类别
#第四列 SOA、NS、A、AAAA都是TYPE记录类型
#第五列 此记录对应的具体值,根据TYPE不一样,写法会有不同
-------------------------------------------------------------------------------------------------
#说一下第一行的内容
@ 604800 IN SOA localhost. root.localhost. ( 2 604800 86400 2419200 604800 )
#localhost. DNS服务器的名称
#root.localhost. DNS管理员邮箱 一般邮箱都是xx@xx.xxx 因为@在本配置文件中有特殊含义指代域名 所以使用.来代替@
#( 2 604800 86400 2419200 604800 ) 单位秒
#2 当前数据库的版本号,主从服务器要同步数据,此字段就是数据更新的标识
#604800 从服务器拉取数据的时间间隔,从服务器拉取数据的时间间隔
#86400 从服务器同步失败后重试时间间隔,上次同步失败后,间隔多久重试
#2419200 从服务器同步失败超过多长时间从服务器失败,同步失败时长超过此值,则认为从服务器数据无效
#604800 不存在的记录缓存时长,当查询一个不存在的解析记录时,该记录在指定时间内直接返回不存在
2.展开写法
glusterfs.com. 86400 IN SOA glusterfs-dns. admin.gluster.com. ( 123 3H 15M 1D 1W )
glusterfs.com. 86400 IN NS dns1.glusterfs.com.
dns1.glusterfs.com. 86400 IN A 172.29.7.10
node1.glusterfs.com. 86400 IN A 172.29.7.21
node2.glusterfs.com. 86400 IN A 172.29.7.22
node3.glusterfs.com. 86400 IN A 172.29.7.23
node4.glusterfs.com. 86400 IN A 172.29.7.24
#glusterfs.com. 86400 IN SOA glusterfs-dns. admin.gluster.com. ( 123 3H 15M 1D 1W ) SOA标记权威区域的开始
#glusterfs.com. 86400 IN NS dns1.glusterfs.com. 收到解析请求后解析到dns1.glusterfs.com.
#dns1.glusterfs.com. 86400 IN A 172.29.7.10 这个A记录表示DNS在那个主机
#node1.glusterfs.com. 86400 IN A 172.29.7.21 把具体的域名解析到相应的IP
3.CLASS资源记录类别
#IN the Internet/互联网,最常用的
#CS CSNET,己被废弃
#CH CHAOS ,一种早期协议
#HS Hesiod
4.TYPE记录类型
#A internet Address,将FQDN解析成IPV4地址,这是最常用的一种解析类型
#AAAA IPV6 internet Address,将FQDN解析成IPV6地址
#CNAME the canonical name for an alias,记录别名,将域名解析到另一个域名
#HINFO host information,主机信息
#KEY 安全密钥记录
#MD 被废弃,使用 MX
#MF 被废弃,使用 MX
#MINFO mailbox or mail list information,邮箱或邮件列表信息
#MX Mail eXchanger,用于邮件交换,指定邮件服务器
#NS Name Server,将解析指向另外一个DNS,表示由被指定的DNS解析当前记录
#PTR a domain name pointer,域名指针,用IP地址反向解析域名
#SOA a marks the start of a zone of authority,标记权威区域的开始
#SRV service and protocol,服务和协议
#TXT text strings,文本字符串,此类型值长度限定不超过512个字符
#WKS a well known service description/众所周知的服务描述
3、DNS主从配置
主从服务之间数据同步,有两种方式
1. 主服务器向从服务器推送数据(PUSH)
2. 从服务器向主服务器拉取数据(PULL)
主从配置
DNS Master 172.29.7.10 dns主服务器
DNS Slave 172.29.7.11 dns从服务器
Test node 172.29.7.101 测试机
域名 glusterfs.com
DNS Master 配置
#修改主机名称
[root@c7-dns-10 ~]# hostnamectl set-hostname c7-dns-10
#配置文件开启selinux警告模式
[root@c7-dns-10 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
#动态开启selinux警告模式
[root@c7-dns-10 ~]# setenforce 0
#开机不启动防火墙并关闭防火墙
[root@c7-dns-10 ~]# systemctl disable --now firewalld
#固定IP
[root@c7-dns-10 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="none"
IPADDR=172.29.7.10
PREFIX=24
GATEWAY=172.29.7.254
DNS1=114.114.114.114
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
#重启网卡
[root@c7-dns-10 ~]# nmcli connection reload
[root@c7-dns-10 ~]# nmcli connection up ens33
#修改时区
[root@c7-dns-10 ~]# timedatectl set-timezone Asia/Shanghai
#配置时间同步
[root@c7-dns-10 ~]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
##禁用0,1,2,3 添加阿里云一行
server ntp1.aliyun.com iburst
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
......
#重启时间同步程序并设为开机自启
[root@c7-dns-10 ~]# systemctl restart chronyd
[root@c7-dns-10 ~]# systemctl enable --now chronyd
#查看时间是否同步
[root@c7-dns-10 ~]# chronyc -n sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? 120.25.115.20 2 6 1 9 -1253us[-1253us] +/- 28ms
#安装dns服务器 bind:dns服务器 bind-utils:dns工具包
[root@c7-dns-10 ~]# yum -y install bind bind-utils
--------------------------------------------------------------------------------------------------------------------------
#在named.rfc1912.zones中间配置文件添加需要解析的域名
[root@c7-dns-10 ~]# tail -n 5 /etc/named.rfc1912.zones
zone "glusterfs.com" IN {
type master;
file "/etc/named/db.glusterfs.com";
};
#写具体解析文件 路径由上面的中间配置文件里的file指定
[root@c7-dns-10 ~]# cat /etc/named/db.glusterfs.com
glusterfs.com. 86400 IN SOA glusterfs-dns. admin.gluster.com. ( 123 3H 15M 1D 1W )
glusterfs.com. 86400 IN NS dns1.glusterfs.com.
dns1.glusterfs.com. 86400 IN A 172.29.7.10
node1.glusterfs.com. 86400 IN A 172.29.7.21
node2.glusterfs.com. 86400 IN A 172.29.7.22
node3.glusterfs.com. 86400 IN A 172.29.7.23
node4.glusterfs.com. 86400 IN A 172.29.7.24
#修改属主属组和权限
[root@c7-dns-10 ~]# chmod 644 /etc/named/db.glusterfs.com
[root@c7-dns-10 ~]# chown root:root /etc/named/db.glusterfs.com
#开机自启dns服务器
[root@c7-dns-10 ~]# systemctl enable --now named.service
#修改主配置文件,使其可以解析到主机
[root@c7-dns-10 ~]# vim /etc/named.conf
options {
##禁用这三个选项
##此配置表示DNS服务只监听了本机127.0.0.1的53端口,如果对外提供DNS服务,可以将此行注释或值改成any
#listen-on port 53 { 127.0.0.1; };
##监听IPV6的53端口,配置方法同上
#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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
##此配置表示仅本机可以使用DNS服务的解析查询功能,如果对外提供DNS服务,可以将此行注释或值改成any
#allow-query { localhost; };
#测试
[root@c7-dns-10 ~]# host node1.glusterfs.com 172.29.7.10
Using domain server:
Name: 172.29.7.10
Address: 172.29.7.10#53
Aliases:
node1.glusterfs.com has address 172.29.7.21
DNS Slave 配置
#初始化配置,不多介绍,不同点我会标注
[root@c7-dns-11 ~]# hostnamectl set-hostname c7-dns-11
[root@c7-dns-11 ~]# setenforce 0
[root@c7-dns-11 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@c7-dns-11 ~]# systemctl disable --now firewalld
[root@c7-dns-11 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="none"
IPADDR=172.29.7.11
PREFIX=24
GATEWAY=172.29.7.254
DNS1=114.114.114.114
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
[root@c7-dns-11 ~]# nmcli connection reload
[root@c7-dns-11 ~]# nmcli connection up ens33
[root@c7-dns-11 ~]# timedatectl set-timezone Asia/Shanghai
#此处可以是阿里云,也可以是DNS Master主机
[root@c7-dns-11 ~]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 172.29.7.10 iburst
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
......
[root@c7-dns-11 ~]# systemctl restart chronyd
[root@c7-dns-11 ~]# systemctl enable --now chronyd
[root@c7-dns-11 ~]# chronyc -n sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? 172.29.7.10 0 7 0 - +0ns[ +0ns] +/- 0ns
[root@c7-dns-11 ~]# yum -y install bind bind-utils
--------------------------------------------------------------------------------------------------------------------------
[root@c7-dns-11 ~]# vim /etc/named.conf
options {
##禁用这三个选项
##此配置表示DNS服务只监听了本机127.0.0.1的53端口,如果对外提供DNS服务,可以将此行注释或值改成any
#listen-on port 53 { 127.0.0.1; };
##监听IPV6的53端口,配置方法同上
#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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
##此配置表示仅本机可以使用DNS服务的解析查询功能,如果对外提供DNS服务,可以将此行注释或值改成any
#allow-query { localhost; };
[root@c7-dns-11 ~]# tail -n 6 /etc/named.rfc1912.zones
zone "glusterfs.com" IN {
type slave; #设置为slave
masters {172.29.7.10;}; #master节点ip为172.29.7.10
file "/etc/named/db.glusterfs.com"; #向master节点同步的配置文件路径,该文件不需要自己手动写,配置完成后会自动生成
};
[root@c7-dns-11 ~]# chmod g=rwx /etc/named
[root@c7-dns-11 ~]# systemctl restart named
[root@c7-dns-11 ~]# systemctl enable --now named
[root@c7-dns-11 ~]# ll -d /etc/named/db.glusterfs.com
-rw-r--r--. 1 named named 406 Jan 31 23:28 /etc/named/db.glusterfs.com
Test node 测试
root@u-test-101:~# host node1.glusterfs.com 172.29.7.11
Using domain server:
Name: 172.29.7.11
Address: 172.29.7.11#53
Aliases:
node1.glusterfs.com has address 172.29.7.21
4、DNS子域
将子域委派给其它的DNS服务器解析,实现分布式DNS服务
子域配置
DNS Master 172.29.7.10
DNS Slave 172.29.7.11
DNS Subdomain 172.29.7.12
Test node 172.29.7.101
域名 glusterfs.com
子域名 test.glusterfs.com
DNS Master
#基础配置同主从一样
#需要修改的内容
[root@c7-dns-10 ~]# cat /etc/named/db.glusterfs.com
#修改一下版本号,同步一下
glusterfs.com. 86400 IN SOA glusterfs-dns. admin.gluster.com. ( 124 3H 15M 1D 1W )
glusterfs.com. 86400 IN NS dns1.glusterfs.com.
#添加子域名DNS解析
test.glusterfs.com. 86400 NS test-dns.glusterfs.com.
dns1.glusterfs.com. 86400 IN A 172.29.7.10
#指定子域解析服务器
test-dns.glusterfs.com. 86400 IN A 172.29.7.12
node1.glusterfs.com. 86400 IN A 172.29.7.21
node2.glusterfs.com. 86400 IN A 172.29.7.22
node3.glusterfs.com. 86400 IN A 172.29.7.23
node4.glusterfs.com. 86400 IN A 172.29.7.24
#重新加载配置
[root@c7-dns-10 ~]# rndc reload
#可以看见slave server已经同步成功了
[root@c7-dns-10 ~]# ll /etc/named/db.glusterfs.com
-rw-r--r-- 1 root root 452 Feb 1 14:26 /etc/named/db.glusterfs.com
[root@c7-dns-11 ~]# ll /etc/named/db.glusterfs.com
-rw-r--r-- 1 named named 522 Feb 1 14:30 /etc/named/db.glusterfs.com
DNS Slave
#同主从配置
DNS Subdomain
[root@c7-dns-12 ~]# tail -n 4 /etc/named.rfc1912.zones
zone "test.glusterfs.com" IN {
type master;
file "/etc/named/db.test.glusterfs.com";
};
[root@c7-dns-12 ~]# cat /etc/named/db.test.glusterfs.com
test.glusterfs.com. 86400 IN SOA test.glusterfs-dns. admin-test.gluster.com. ( 124 3H 15M 1D 1W )
test.glusterfs.com. 86400 NS test-dns.glusterfs.com.
test-dns.glusterfs.com. 86400 IN A 172.29.7.12
www.test.glusterfs.com. 86400 IN A 172.29.7.99
Test node
root@u-test-101:~# host www.test.glusterfs.com 172.29.7.10
Using domain server:
Name: 172.29.7.10
Address: 172.29.7.10#53
Aliases:
www.test.glusterfs.com has address 172.29.7.99
root@u-test-101:~# host www.test.glusterfs.com 172.29.7.11
Using domain server:
Name: 172.29.7.11
Address: 172.29.7.11#53
Aliases:
www.test.glusterfs.com has address 172.29.7.99