1. 程式人生 > 其它 >實現正向解析dns服務

實現正向解析dns服務

一、實現DNS正向主伺服器

1.實驗目的

搭建DNS正向主伺服器,實現web伺服器基於FQDN的訪問

2.環境要求

需要三臺主機
DNS服務端:10.0.0.14
web伺服器:10.0.0.12
DNS客戶端:10.0.0.11

3.前提準備

關閉SElinux
關閉防火牆
時間同步

4.實現步驟

1)在DNS服務端安裝bind

[root@centos7 ~]# yum install -y bind

2)修改bind 配置檔案

[root@centos7 ~]# vim /etc/named.conf
#註釋掉下面兩行
// listen-on port 53 { 127.0.0.1; };
// allow-query     { localhost; };
[root@centos7 ~]# vim /etc/named.rfc1912.zones 
#加上下面內容
zone "magedu.org" IN {
   type master;
   file  "magedu.org.zone";
};

3)DNS區域資料庫檔案

[root@centos7 ~]# cp  /var/named/named.localhost /var/named/magedu.org.zone -a

#如果沒有加-p選項,需要修改所有者或許可權。chgrp named magedu.org.zone

[root@centos7 ~]# vim /var/named/magedu.org.zone
$TTL 1D
@ IN SOA master admin.magedu.org. (
 
2019042210 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS master master A 10.0.0.14 www A 10.0.0.12

4)檢查配置檔案和資料庫檔案格式,並啟動服務

[root@centos7 ~]# named-checkconf
[root@centos7 ~]# named-checkzone magedu.org /var/named/magedu.org.zone


[root@centos7 ~]# systemctl start named #第一次啟動服務
[root@centos7 
~]# rndc reload #不是第一次啟動服務

5)實現WEB服務

#安裝http服務
[root@centos7 html]# yum install -y httpd
#配置主頁面
[root@centos7 html]# echo www.magedu.org > /var/www/html/index.html
#啟動服務
[root@centos7 html]# systemctl start httpd

6)在客戶端實現測試

[root@centos7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=10.0.0.8
#centos7 以上版執行現下面命令生效
[root@centos8 ~]# nmcli con reload
[root@centos8 ~]# nmcli con up eth0
#centos 6 執行下面命令生效
[root@centos7 ~]# service network restart
#有以下記錄,算是成功
[root@centos7 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 10.0.0.14

#測試網頁,能顯示就是成功
[root@centos7 ~]# curl www.magedu.org
www.magedu.org

 

記錄於2022-3-30 weilan