1.dns
domain name service(域名解析服务)关于客户端:/etc/resolv.conf dns指向文件nameserver 172.25.254.20关于服务端bind 安装包named 服务名称/etc/named.conf 主配置文件/var/named 数据目录端口 53关于报错信息:no servers could be reached 服务无法访问(服务开启?火墙?网络?端口?)服务启动失败 配置文件写错 journalctl -xe查询错误dig 查询状态NOERROR 表示查询成功REFUSED 服务拒绝访问SERVFAIL 查询记录失败,(dns服务器无法到达上级,拒绝缓存)NXDOMAIN 此域名A记录在dns中不存在![]()
2. dns服务的安装与启用
安装dnf install bind.x86_64 -y 启用systemctl enable --now namedfirewall-cmd --permanent --add-service=dnsfirewall-cmd --reloadvim /etc/named.conf11 listen-on port 53 { any; }; 在本地所有网络接口上开启53端口19 allow-query { any; }; 允许查询A记录的客户端列表34 dnssec-validation no; 禁用dns检测使dns能够缓存外部信息到本纪systemctl restart named高速缓存dns20 forwarders { 114.114.114.114; };![]()
![]()
测试高速缓存 需要两个主机都编辑好 vim/etc/resolv.conf
3.dns的正向解析
vim /etc/named.rfc1912.zonezone "westos.com" IN { 维护的域名type master; 当前服务器位主dnsfile "westos.com.zone"; 域名A记录文件allow-update { none; }; 允许更新主机列表};![]()
cd /var/named/
cp -p named.localhost westos.com.zone$TTL 1D TIME-TO-LIVE(dns地址保存时间长度)@ IN SOA dns.westos.com. root.westos.com ( #SOA授权起始(Start of Authority)0 ; serial 域名版本序列号1D ; refresh 刷新时间(辅助dns)1H ; retry 重试时间(辅助dns)1W ; expire 过期时间(辅助dns,查询失败过期停止对辅 助域名的应答)3H ) ; minimum A记录最短有效期NS dns.westos.com.
dns A 192.168.0.20www CNAME westos.a.westos.com. 规范域名westos.a A 192.168.0.111 正向解析记录westos.a A 192.168.0.112westos.com. MX 1 192.168.0.20. 邮件解析记录![]()
systemctl restart nameddig www.westos.com 查询正向解析dig -t mx westos.com 邮件解析记录查询![]()
4.dns的反向解析
vim /etc/named.rfc1912.zones![]()
cd /var/named/cp -p named.loopback 172.25.254.ptrvim 172.25.254.0.ptrsystemctl restart named![]()
测试:
dig -x 192.168.0.11![]()
5.dns的双向解析
实验环境:客户端2台192.168.0网段1.1.1网段 ifconfig ens160 1.1.1.200 netmask 255.255.255.0![]()
服务端1台2个网段的
172.25.254.1001.1.1.100ifconfig ens160 172.25.254.20 netmask 255.255.255.0![]()
在1.1.1网段的客户主机中vim /etc/resolv.confnameserver 1.1.1.100在172.25.254网段的客户主机中vim /etc/resolv.confnameserver 172.25.254.20![]()
配置方式
cd /var/named/cp -p westos.com.zone westos.com.intervim westos.com.inter
cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.intersvim /etc/named.rfc1912.inters![]()
![]()
vim /etc/named.conf
systemctl restart named测试:分别在2个网段的主机中作同样域名的地址解析得到的A记录不同
6.dns集群
主dns:zone "westos.com" IN {type master;file "westos.com.zone";allow-update { none; };also-notify { 192.25.254.200; }; 主动通知的辅助dns主机}![]()
vim /var/named/westos.com.zone
辅助dns
dnf install bind -yfirewall-cmd --add-service=dnsvim /etc/named.conflisten-on port 53 { any; };allow-query { any; };dnssec-validation no;
vim /etc/named.rfc1912.zone![]()
systemctl restart named![]()
更新此位置辅助dns 会同步更新
7.dns的更新
dns基于ip地址的更新:在dns中设定:vim /etc/named.rfc1912.zoneszone "westos.com" IN {type master;file "westos.com.zone";allow-update { 192.168.0.10; }; ##允许指定客户端更新westos域also-notify { 192.168.0.30; };};![]()
测试:在192.168.0.10[root@rhel7_node1 ~]# nsupdate> server 192.168.0.20> update add hello.westos.com 86400 A 192.168.0.111 新曾A记录> send> update delete hello.westos.com 删除A记录> send
dns基于key更新的方式:dnssec-keygen -a HMAC-SHA256 -b 128 -n HOST westos
cp -p /etc/rndc.key /etc/westos.keyvim /etc/westos.keykey "westos" {algorithm hmac-sha256;secret "SB1tQcLaWeroU9lGW21zeA==";};![]()
vim /etc/named.conf43 include "/etc/wesots.key";![]()
vim /etc/named.rfc1912.zoneszone "westos.com" IN {type master;file "westos.com.zone";allow-update { key westos; };also-notify { 172.25.254.200; };};![]()
systemctl restart namednsupdate -k /mnt/Kwestos.+163+26695.private> server 172.25.254.100> update add hello.westos.com 86400 A 172.25.254.111> send> quit![]()
8.ddns
dnf instsall dhcp-server -yvim /etc/dhcpd/dhcpd.conf![]()
dns的key更新测试:设定测试主机网络工作方式为dhcp设定主机名称test.westos.com重启网络dig test.westos.com可以得到正确解析