一、正向解析 (把域名解析为IP)
编号 | 主机名 | ip地址 | 说明 | 修改 |
---|---|---|---|---|
1 | web服务器 | 192.168.2.23 | 发布部署web服务 | 发布了一个nginxweb服务 |
2 | dns服务器 | 192.168.2.22 | 用于解析域名和ip地址 | 1.安装bind,2.配置了conf,zones,zone,3.检查了三个文件,启动 |
3 | client主机 | 192.168.2.21 | 用于模拟客户机 | 修改了dns的访问主机 临时修改echo "nameserver 192.168.2.25",永久修改:vim /etc/sysconfig/network-scirpts/ifcfg-ens33 将原来的DNS1 DNS修改为我们现在自己配置的主机 |
1.基础配置
(1)设置主机名
hostnamectl set-hostname xxxx
(2)设置IP地址
(3)关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firrewalld
setenforce 0
vim /etc/selinux/config
2.配置客户端
在客户端上配置浏览器
[root@client ~]# yum -y install elinks
[root@client ~]# elinks
[root@client ~]# echo "nameserver 192.168.2.22" > /etc/resolv.conf
[root@client ~]# cat /etc/resolv.conf
nameserver 192.168.2.22
3.配置dns服务器
[root@dns ~]# yum -y install bind
[root@dns ~]# yum list installed | grep bind
[root@dns ~]# vim /etc/named.conf
[root@dns ~]# vim /etc/named.rfc1912.zones
[root@dns ~]# cd /var/named
[root@dns named]# ls
[root@dns named]# cp -p named.localhost hui.zone
[root@dns named]# vim hui.zone
[root@dns named]# named-checkconf /etc/named.conf
[root@dns named]# named-checkconf /etc/named.rfc1912.zones
[root@dns named]# named-checkzone hui.zone hui.zone
[root@dns named]# systemctl restart named
4.配置web服务器
[root@web ~]# yum -y install nginx
启动服务
[root@web ~]# nginx
5.补充
设置解析方式,都是在zone文件中
named.conf解决权限
named.rfc1912.zone 解决解析方式
二、反向解析 (将IP解析为域名)
逆向解析
(1).客户端准备工作:
域名返回IP
[root@client ~]# yum -y install bind-utils.x86_64
nslookup www.hui
(2).配置DNS:
配置反向解析
(1).配置/etc/named.rfc1912.zones 文件
[root@dns named]# vim /etc/named.rfc1912.zones
[root@dns named]# pwd/var/named
[root@dns named]# ls
(2)备份文件
[root@dns named]# cp -p named.loopback 192.168.2.zone
(3)配置192.168.2.zone文件
[root@dns named]# vim 192.168.2.zone
解释:web服务器地址的最后一位 PTR 域名
(4)检查文件
[root@dns named]# named-checkconf /etc/named.rfc1912.zones
[root@dns named]# named-checkzone 192.168.2.zone 192.168.2.zone
(5).启动服务
[root@dns named]# systemctl restart named
(3).配置web服务器:
安装nginx
[root@web ~]# yum -y install nginx
启动服务
[root@web ~]#nginx
(4).客户端访问:
可以通过域名解析出IP地址(正向解析)
[root@client ~]# nslookup www.hui
Server: 192.168.2.22
Address: 192.168.2.22#53
Name: www.hui
Address: 192.168.2.23
可以通过IP地址解析出域名(反向解析)
[root@client ~]# nslookup 192.168.2.23
23.2.168.192.in-addr.arpa name = www.hui.2.168.192.in-addr.arpa.
重启network服务后,只能访问到百度,域名访问不到
[root@client ~]# systemctl restart network
[root@client ~]# cat /etc/resolv.conf
nameserver 8.8.8.8
[root@client ~]# nslookup www.baidu.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 180.101.50.188
Name: www.a.shifen.com
Address: 180.101.50.242
Name: www.a.shifen.com
Address: 240e:e9:6002:15a:0:ff:b05c:1278
Name: www.a.shifen.com
Address: 240e:e9:6002:15c:0:ff:b015:146f
[root@client ~]# nslookup www.hui
;; connection timed out; no servers could be reached
[root@client ~]# nslookup 192.168.2.23
** server can't find 23.2.168.192.in-addr.arpa.: NXDOMAIN
将DNS服务器的地址 重定向到/etc/resolv.conf文件中,就可以访问到域名了(但是不能访问到百度)
[root@client ~]# echo "nameserver 192.168.2.22" > /etc/resolv.conf
[root@client ~]# nslookup 192.168.2.23
23.2.168.192.in-addr.arpa name = www.hui.2.168.192.in-addr.arpa.
[root@client ~]# nslookup www.hui
Server: 192.168.2.22
Address: 192.168.2.22#53
Name: www.hui
Address: 192.168.2.23
三、多域名
(1).配置/etc/named.rfc1912.zones文件
[root@dns named]# vim /etc/named.rfc1912.zones
[root@dns named]# ls
备份文件
[root@dns named]# cp -p hui.zone haha.zone
[root@dns named]# ls
(2).配置zone文件
[root@dns named]# vim haha.zone
(3).重启服务
[root@dns named]# systemctl restart named
(4).客户端访问:
[root@client ~]# nslookup ooo.haha
Server: 192.168.2.22
Address: 192.168.2.22#53
Name: ooo.haha
Address: 192.168.2.23
[root@client ~]# nslookup www.hui
Server: 192.168.2.22
Address: 192.168.2.22#53
Name: www.hui
Address: 192.168.2.23
四、搭建时间服务器
同步时间
ntpdate cn.ntp.org.cn
要求集群服务器主机的时间同步
不可能每一台主机都访问一次ntpdate cn.ntp.org.cn 流量大,效率低
只放一台主机做内网的ntp服务器,这台主机定时访问外网
[root@client ~]# date -s "2024-7-20 12:34:56"
2024年 07月 20日 星期六 12:34:56 CST
[root@client ~]# date2024年 07月 20日 星期六 12:35:03 CST
[root@client ~]# yum -y install ntpdate.x86_64
[root@client ~]# ntpdate cn.ntp.org.cn
[root@client ~]# date
2024年 07月 24日 星期三 15:13:53 CST
配置ntp服务器
[root@ntp ~]# yum -y install ntp
[root@ntp ~]# vim /etc/ntp.conf
restrict 192.168.2.0 mask 255.255.255.0
同步时间:
[root@ntp ~]# ntpdate cn.ntp.org.cn
24 Jul 15:06:27 ntpdate[1738]: adjust time server 120.197.116.202 offset 0.001612 sec
[root@ntp ~]# systemctl start ntpd
计划任务:每天4点钟更新
[root@ntp ~]# which ntpdate
/usr/sbin/ntpdate
[root@ntp ~]# crontab -e
五、DNS主从配置
(1).基础要求说明,一般常见的主从架构服务的要求
1.master和slave的系统时间保持一致
2.slave服务器上安装相应的软件(系统版本,软件版本)保持一致
3.根据需求修改相应的配置文件 master和slave都应修改
4.主从同步的核心是slave同步master上的区域文件
配置从服务器,备份到从服务器,主从架构,主要是同步zone文件
(2).主服务器配置
(1).安装ntpdate
[root@dns named]# yum -y install ntpdate
(2).与时间服务器同步时间
[root@dns named]# ntpdate 192.168.2.24
(3).设置允许从服务器同步文件
[root@dns named]# vim /etc/named.conf
第五行:allow-transfer {192.168.2.25;}; 从服务器地址**
(4).检查文件
[root@dns named]# named-checkconf /etc/named.conf
(5).启动服务
[root@dns named]# systemctl restart named
(3).从服务器配置
(1).安装ntpdate
[root@dns named]# yum -y install ntpdate
(2).与时间服务器同步时间
[root@dns named]# ntpdate 192.168.2.24
(3).安装bind
因为从(sla)服务器在主服务器下线时需要工作
[root@sla ~]# yum -y install bind
(4).查看是否安装好bind
[root@sla ~]# yum list installed | grep bind
(5).修改/etc/named.conf文件
[root@sla ~]# vim /etc/named.conf
(6).检查named.conf文件
[root@sla ~]# named-checkconf /etc/named.conf
(7).修改/etc/named.rfc1912.zones 文件
[root@sla ~]# vim /etc/named.rfc1912.zones
(8).检查zones文件
[root@sla ~]# named-checkconf /etc/named.rfc1912.zones
(9).重启服务
[root@sla ~]# systemctl restart named
[root@sla ~]# ls /var/named/slaves
hui.zone
(4).客户端访问
可以访问主服务器
[root@client ~]# echo "nameserver 192.168.2.22" > /etc/resolv.conf
[root@client ~]# nslookup www.hui
Server: 192.168.2.22
Address: 192.168.2.22#53
Name: www.hui
Address: 192.168.2.23
可以访问从服务器
[root@client ~]# echo "nameserver 192.168.2.25" > /etc/resolv.conf
[root@client ~]# nslookup www.hui
Server: 192.168.2.25
Address: 192.168.2.25#53
Name: www.hui
Address: 192.168.2.23
六、访问一个ip可以解析多个域名
(1).配置/etc/named.rfc1912.zones 文件
配置正向解析:
[root@dns ~]# vim /etc/named.conf
[root@dns ~]# vim /etc/named.rfc1912.zones
[root@dns ~]# cd /var/named
[root@dns named]# ls
[root@dns named]# cp -p named.localhost xxx.zone
[root@dns named]# cp -p named.localhost aaa.zone
[root@dns named]# vim xxx.zone
[root@dns named]# vim aaa.zone
[root@dns named]# systemctl restart named
配置反向解析:
[root@dns named]# vim /etc/named.rfc1912.zones
[root@dns named]# pwd
/var/named
[root@dns named]# ls
data hui.zone named.empty named.loopbackdynamic named.ca named.localhost slaves
(2)备份文件
[root@dns named]# cp -p named.loopback 192.168.2.zone
(3)配置192.168.2.zone文件
[root@dns named]# systemctl restart named
客户端测试: