1. 程式人生 > 實用技巧 >linux系統中部署DNS從伺服器

linux系統中部署DNS從伺服器

DNS域名解析服務的三種伺服器:

主伺服器:管理域名和IP地址的對應關係

從伺服器:同步域名和IP地址的對應關係(緩解跟伺服器壓力,提高解析速度)

快取伺服器:轉發域名和IP地址的對應關係(緩解根伺服器壓力,提高解析速度)

DNS從伺服器要解決的問題:

從主伺服器中獲取指定的區域資料檔案,起到備份同步和負載均衡的作用,緩解主伺服器壓力,提高DNS解析效率。

下面實驗中要用到兩臺虛擬機器,分別為PC1(主伺服器)和PC2(從伺服器)。IP分別為192.168.10.10和192.168.10.20。

1、檢視主伺服器和從伺服器基本資訊,測試聯通性

[root@PC1 ~]# ifconfig | head -n 3  ## 檢視主伺服器IP
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.10
netmask 255.255.255.0 broadcast 192.168.10.255 inet6 fe80::20c:29ff:fe66:37f7 prefixlen 64 scopeid 0x20<link>
[root@PC2 ~]# ifconfig | head -n 3  ## 檢視從伺服器IP
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.20  netmask 255.255.255.0  broadcast 192.168
.10.255 inet6 fe80::20c:29ff:fe25:bb3e prefixlen 64 scopeid 0x20<link> [root@PC2 ~]# ping -c 3 192.168.10.10 ## 測試從伺服器和主伺服器的連通性,沒有問題 PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data. 64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.222 ms 64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.202
ms 64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.228 ms --- 192.168.10.10 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.202/0.217/0.228/0.016 ms

2、主伺服器上一實驗已經配置好BIND服務,只需給從伺服器配置好BIND服務

[root@PC2 network-scripts]# yum install bind-chroot  ## 安裝bind服務
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package bind-chroot.x86_64 32:9.9.4-14.el7 will be installed
--> Processing Dependency: bind = 32:9.9.4-14.el7 for package: 32:bind-chroot-9.9.4-14.el7.x86_64
--> Running transaction check
---> Package bind.x86_64 32:9.9.4-14.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================
 Package                Arch              Version                      Repository        Size
==============================================================================================
Installing:
 bind-chroot            x86_64            32:9.9.4-14.el7              rhel7             81 k
Installing for dependencies:
 bind                   x86_64            32:9.9.4-14.el7              rhel7            1.8 M

Transaction Summary
==============================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 1.8 M
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
----------------------------------------------------------------------------------------------
Total                                                         189 MB/s | 1.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 32:bind-9.9.4-14.el7.x86_64                                                1/2 
  Installing : 32:bind-chroot-9.9.4-14.el7.x86_64                                         2/2 
rhel7/productid                                                        | 1.6 kB  00:00:00     
  Verifying  : 32:bind-9.9.4-14.el7.x86_64                                                1/2 
  Verifying  : 32:bind-chroot-9.9.4-14.el7.x86_64                                         2/2 

Installed:
  bind-chroot.x86_64 32:9.9.4-14.el7                                                          

Dependency Installed:
  bind.x86_64 32:9.9.4-14.el7                                                                 

Complete!
[root@PC2 network-scripts]# vim /etc/named.conf   ## 修改主配置檔案,修改第11行和第17行
  1 //
  2 // named.conf
  3 //
  4 // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
  5 // server as a caching only nameserver (as a localhost DNS resolver only).
  6 //
  7 // See /usr/share/doc/bind*/sample/ for example named configuration files.
  8 //
  9 
 10 options {
 11         listen-on port 53 { any; };  ## 表示所有的IP均可提供DNS服務
 12         listen-on-v6 port 53 { ::1; };
 13         directory       "/var/named";
 14         dump-file       "/var/named/data/cache_dump.db";
 15         statistics-file "/var/named/data/named_stats.txt";
 16         memstatistics-file "/var/named/data/named_mem_stats.txt";
 17         allow-query     { any; };  ## 表示允許任何人使用DNS查詢服務
 18 
 19         /* 
 20          - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
 21          - If you are building a RECURSIVE (caching) DNS server, you need to enable 
 22            recursion. 

修改從伺服器網絡卡引數,將DNS服務改為本機的IP:

[root@PC2 Desktop]# systemctl restart named  ## 重啟bind服務
[root@PC2 Desktop]# systemctl restart network  ## 重啟網絡卡服務

2、