目录
1.关于dns的名词解释
- dns解析:上网将域名解析为ip ,而dns:domain name service(域名解析服务)
- 实验环境:
客户端:
etc/resolv.conf dns指向文件
nameserver 172.25.254.112
测试:
host www.baidu.com 地址解析命令
dig www.baidu.com 地址详细解析信息命令
服务端:(可上网,ip=172.25.254.29)
bind :安装包
named :服务名称
/etc/named.conf :主配置文件
/var/named :数据目录
端口 :53
关于报错信息:
1.no servers could be reached :服务无法访问(服务开启?火墙?网络?端口?)
2.服务启动失败 :配置文件写错 journalctl -xe查询错误
3.dig 查询状态
NOERROR 查询成功 REFUSED 服务拒绝访问 SERVFAIL 查询记录失败, NXDOMAIN 此域名A记录在dns中不存在
2.dns服务的安装与启用
安装
dnf install bind.x86_64 -y
启用
系统启动:
systemctl enable --now named
火墙端口开放:
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
为所有端口对外提供接口
vim /etc/named.conf :编辑主配置文件
具体内容:
listen-on port 53 { any; }; :在本地所有网络接口上开启53端口
allow-query{ any; }; :允许查询A记录的客户端列表
dnssec-validation no; :禁用dns检测使dns能够缓存外部信息到本纪
systemctl restart named :重启服务
3.高速缓存dns
- 主机dig网络,数据信息已经缓存,其余主机再次dig网址,则没有延迟
vim /etc/named.conf :编辑主配置文件
具体内容:
20 forwarders { 114.114.114.114; };
systemctl restart named :重启服务
4.dns的正向解析
- vim /etc/named.rfc1912.zones :编辑子配置文件
zone "westoszl.org" IN { :维护的域名
type master; :当前服务器位主dns
file "westoszl.org.zone"; :域名A记录文件
allow-update { none; }; :允许更新主机列表
};
- cd /var/named/ ; cp -p named.localhost westoszl.org.zone :配置模板
- vim westoszl.org.zone ,详情见截图
- systemctl restart named :重启服务
- 邮件
5.dns的反向解析
- vim /etc/named.rfc1912.zones :编辑子配置文件
zone "254.25.172.in-addr.arpa" IN { :维护的域名
type master; :当前服务器位主dns
file "172.25.254.ptr"; :域名A记录文件
allow-update { none; }; :允许更新主机列表
};
- cd /var/named/ ; cp -p named.localback 172.25.254.ptr :配置模板
- vim westoszl.org.zone ,详情见截图
- systemctl restart named :重启服务
6.dns的双向解析
配置方式:
- cd /var/named/
- cp -p westoszl.org.zone westoszl.org.inter
- vim westoszl.org.inter
- cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.inters
- vim /etc/named.rfc1912.inters
- systemctl restart named
实验环境:
- 客户端2台:172.25.254.212和1.1.1.212网段
- 服务端对应客户端设置两个ip
- 在172.25.254.212的客户端:vim /etc/resolv.conf:nameserver 172.25.254.112(服务端)
- 在1.1.1.212的客户端:vim /etc/resolv.conf:nameserver 1.1.1.112服务端)
7.dns集群
主dns:
- vim /etc/named.rfc1912.zones :编辑子配置文件
zone "westoszl.org" IN { :维护的域名
type master; :当前服务器位主dns
file "westoszl.org.zone"; :域名A记录文件
allow-update { 172.25.254.xxx; }; :允许更新主机列表
};
- vim westoszl.org.zone
副dns:
- dns安装与开启
dnf install bind -y
systemctl enable --now named
firewall-cmd --add-service=dns
firewall-cmd --reload
- vim /etc/named.conf ,编辑主配置文件
listen-on port 53 { any; };
allow-query
{ any; };
dnssec-validation no;
- vim /etc/named.rfc1912.zone :编辑子配置文件
zone "westoszl.org" IN {
type slave; :dns状态为辅助dns
masters { 172.25.254.xxx; }; :主dnsip
file "slaves/westoszl.org.zone"; :同步数据文件
};
- systemctl restart named :重启服务
8.dns更新
dns基于ip地址的更新:
主机server:
- vim /etc/named.rfc1912.zones
zone "westoszl.org" IN {
type master;
file "westoszl.org.zone";
allow-update { 172.25.254.xxx; }; :允许指定客户端更新westoszl域
also-notify { 172.25.254.xxx; };
};
主机client:
[root@client ~]# nsupdate
> server 172.25.254.112
> update add hello.westoszl.org 86400 A 172.25.254.212 :新增A记录
> send
> update delete hello.westoszl.org :删除A记录
> send
dns基于key更新的方式:
主机server:
dnssec-keygen -a HMAC-SHA256 -b 128 -n HOST westoszl
cp -p /etc/rndc.key /etc/westoszl.key
vim /etc/westos.key :编辑密码
key "westos" {
algorithm hmac-sha256;
secret "xxxxxxxx==";
};
vim /etc/named.conf:
include "/etc/wesotszl.key"; 43行
vim /etc/named.rfc1912.zones
zone "westoszl.org" IN {
type master;
file "westoszl.org.zone";
allow-update { key westoszl; };
also-notify { 172.25.254.xxx; };
};
systemctl restart named :系统重启
[root@client ~]# nsupdate -k /mnt/Kwestoszl.+xxx+xxxxx.private
> server 172.25.254.112
> update add tree.westoszl.org 86400 A 172.25.254.212
> send
> quit
主机client:
9.ddns(dhcp+dns)
主机server基本命令:
dnf instsall dhcp-server -y :下载dhcp软件
vim /etc/dhcpd/dhcpd.conf :编辑配置文件:
option domain-name "westoszl.org";
option domain-name-servers 172.25.254.112;
subnet 172.25.254.0netmask 255.255.255.0 {
range 172.25.254.30 172.25.254.90;
option routers 172.25.254.112; }
注 :35行之后全部删除
添加:
key westoszl {
algorithm hmac-sha256;
secret xxxxxxxxxx==;
};
zone westoszl.org. {
primary 127.0.0.1;
key westoszl;
}
systemctl restart dhcpd :重启服务
主机client:
- 网络工作方式为dhcp:
vim /etc/sysconfig/network-scripts/ifcfg-westos:
BOOTPROTO=DHCP
- 设定主机名称:treewestoszl.org
hostnamectl set-hostname tree.westoszl.org
- 重启网络:nmcli connection reload
- dig tree.westoszl.org :测试