DNS域名解析成IP地址------设置主从域名服务器

一、环境安装要求

1、设置 yum 源 永久挂载
2、安装三台虚拟机;一台主域名服务器;一台从域名服务器;一台测试机
3、虚拟和真机防火墙关闭、核心防护关闭 (三台都需要关)
4、BIND包安装:bind ;bind-utils ;bind-libs ;bind-chroot

( 安装命令:yum -y install bind bind-utils bind-libs bind-chroot )

环境安装步骤

1、yum源永久挂载配置:

虚拟机光盘勾上已连接 ;设置 mount /dev/cdrom /mnt 挂载点 ;查看挂载点:df -Th
切换至:cd  /etc/yum.repos.d/ ; 创建文件:mkdir backup ; 移动文件:mv  C*  backup/
复制文件内容至目标文件: cp  backup/CentOS-Base.repo  local.repo
编制目标文件:vi  local.repo
   命令模式下:36dd:删除其他内容,并找到以下内容,更改如下   
   [centos]
   name=CentOS            #####名称
   baseurl=file:///mnt        #####在/mnt文件下查找
   gpgcheck=0              #####0:不检验
   enabled=1               #####1:开启服务
   #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

输入:yum clean all #####清空yum缓存
输入:yum makecache ###### 开启本地yum缓存

编辑永久挂载:vi  /etc/fstab
添加:/dev/cdrom  /mnt  iso9660  defaults  0  0
   :wq

2、3、4、安装虚拟机 ; 关闭防火墙及核心防护 ; 安装yum包:

2、虚拟机安装:配置好IP地址;并重启网卡;ifconfig 查看下

3、关闭防火墙及核心防护命令:

systemctl  status  firewalld     ######查看防火墙状态
systemctl  stop  firewalld      ######关闭防火墙
systemctl  disable  firewalld     ######开机自动关闭防火墙

更改核心防护: vi /etc/selinux/confing 更改此行为disable : SELINUX=disabled

4、yum包安装 :yum -y install bind bind-utils bind-libs bind-chroot

二、开始配置主从域名服务器

全局配置:

vi  /etc/named.conf
 options {
    listen-on port 53 { 20.0.0.11; };
    listen-on-v6 port 53 { ::1; };
    forwarders { 8.8.8.8; 114.114.114.114; };
    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";
    allow-query     { any; };

特定DNS区域配置:

vi  /etc/named.rfc1912.zones
添加正向解析:
zone "bdqn.com" IN {
    type master;
    file "bdqn.com.zone";
    allow-transfer { 20.0.0.12; };
    also-notify { 20.0.0.12; };
};

添加反向解析:
zone "0.0.20.in-addr.arpa" IN {
    type master;
    file "20.0.0.arpa";
    allow-transfer { 20.0.0.12; };
    also-notify { 20.0.0.12; };
};

编辑域名:vi /var/named/bdqn.com.zone

 添加: $TTL 1D
@       IN SOA bdqn.com. admin.bdqn.com. (
                                    0       ;serial
                                    1D      ;refresh
                                    1H      ;retry
                                    1W      ;expire
                                    3H )    ;minimum
   	        NS      @
    	    A      192.168.11.119
www    IN  	A      192.168.11.119
ftp    IN 	A      192.168.11.118
mail   IN  CNAME   www

更改属主:chown named:named /var/named/bdqn.come.zone

编辑ip:vi /var/named/20.0.0.arpa

添加:$TTL 1D
@       IN SOA  bdqn.com. admin.bdqn.com.zone. (
                                    1       ;serial
                                    1D      ;refresh
                                    1H      ;retry
                                    1W      ;expire
                                    3H )    ;minimum
   		 NS     bdqn.com.
  		 A      20.0.0.100
119 IN  PTR     www.bdqn.com.
120 IN  PTR     ftp.bdqn.com.
121 IN  PTR     bbs.bdqn.com.

更改属主:chown named:named /var/named/20.0.0.arpa

进行语法检查:named-checkconf -z /etc/named.conf

重启named: systemctl restart named

三、开始从域名服务器配置

全局配置:

vi  /etc/named.conf
 options {
    listen-on port 53 { 20.0.0.12; };
    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";
    allow-query     { any; };

特定DNS区域配置:

vi  /etc/named.rfc1912.zones
添加正向解析:
      zone "bdqn.com" IN {
    	   type slave;
    	   masters { 20.0.0.11; };
   		   allow-notify { 20.0.0.11; };
   		   file "slaves/bdqn.com.zone";
      };

添加反向解析:
      zone "0.0.20.in-addr.arpa" IN {
   		   type slave;
    	   masters { 20.0.0.11; };
   	   	   allow-notify { 20.0.0.11; };
   		   file "slaves/20.0.0.arpa";
      };

查看文件中无数据: cd /var/named/slaves/ ; ll命令
开启named:systemctl start named
再次查看文件中有数据: ll命令

四、测试机进行测试

添加映射关系

vi  /etc/resolv.conf
添加映射关系:#nameserver 20.0.0.11 ;谁测,另外一条添加#号
             nameserver 20.0.0.12

测试:正向解析

[root@localhost ~]# nslookup www.bdqn.com
Server:         20.0.0.12
Address:        20.0.0.12#53
Name:   www.bdqn.com
Address: 192.168.11.119

[root@localhost ~]# nslookup ftp.bdqn.com
Server:         20.0.0.12
Address:        20.0.0.12#53
Name:   ftp.bdqn.com
Address: 192.168.11.118

测试:反向解析

[root@localhost ~]# nslookup 20.0.0.119
Server:         20.0.0.12
Address:        20.0.0.12#53
119.0.0.20.in-addr.arpa name = www.bdqn.com.

[root@localhost ~]# nslookup 20.0.0.120
Server:         20.0.0.12
Address:        20.0.0.12#53
120.0.0.20.in-addr.arpa name = ftp.bdqn.com.

——————————————————————————————————————————————————————————————————————————————————————————

到此结束,感谢观看,希望对看官有所帮助

你可能感兴趣的:(关于命令)