Linux下搭建DNS服务器

*为openlab搭建web网站,要求基于域名www.openlab.com可以访问网站信息。
自己搭建dns  master、slave服务实现解析。*

1、挂载

    [root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
mount: /dev/sr0 is already mounted or /mnt busy
   /dev/sr0 is already mounted on /run/media/zhangwen/RHEL-7.2 Server.x86_64
   /dev/sr0 is already mounted on /mnt

2、

	[root@localhost ~]# systemctl stop firewalld ------        关闭防火墙
	[root@localhost ~]# setenforce 0-------关闭selinux
	修改主配置文件httpd.conf
	修改主配置文件httpd.conf

在这里插入图片描述
ServerName 0.0.0.0:80

3、 安装httpd和bind

[root@localhost ~]# yum install httpd
Loaded plugins: langpacks, product-id, search-disabled-repos, 			subscription-manager
This system is not registered to Red Hat Subscription Management. 		You 	can use subscription-manager to register.
Package httpd-2.4.6-40.el7.x86_64 already installed and latest version
Nothing to do

[root@localhost ~]# yum install bind
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package 32:bind-9.9.4-29.el7.x86_64 already installed and latest version
Nothing to do

4、本地源配置文件
Linux下搭建DNS服务器_第1张图片
5、编辑主配置文件:

options {
        listen-on port 53 { 192.168.43.89; };
        directory "/var/named";
        allow-transfer { 192.168.43.162; };
};
zone "baidu.com" IN {
        type master; 
        file "named.baidu.com";
};
zone "qq.com" IN {
        type master;
        file "named.qq.com";
};
zone "43.168.192.in-addr.arpa" IN {
        type master;
        file "named.192.168.43";
};

6、正向解析配置文件:

$TTL 1D
@       IN      SOA     @       admin.admin.com. (
                                                0
                                                1D
                                                1H
                                                1W
                                                1H )
        IN      NS      ns.baidu.com.
        IN      MX      10 mail.baidu.com.
ns      IN      A       192.168.43.89
mail    IN      A       192.168.43.89
www     IN      A       192.168.43.89
ftp     IN      A       192.168.43.89
sftp    IN      CNAME   ftp

7 、反向解析的配置文件:

$TTL 1D
@       IN      SOA     @       admin.admin.com (
                                                0
                                                1D
                                                1H
                                                1W
                                                1D )
        IN      NS      ns.baidu.com. 
        IN      NS      ns.qq.com.
89      IN      PTR     ns.baidu.com.
89      IN      PTR     ns.qq.com.
90      IN      PTR     ftp.baidu.com.
90      IN      PTR     ftp.qq.com.
89      IN      PTR     www.qq.com.
89      IN      PTR     www.baidu.com
sftp    IN      CNAME   ftp

8、更改 DNS服务器的IP地址

Linux下搭建DNS服务器_第2张图片

9、 正向测试

[root@localhost ~]# dig -t A www.baidu.com

; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7 <<>> -t A www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43906
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com.			IN	A

;; ANSWER SECTION:
www.baidu.com.		86400	IN	A	192.168.44.131

;; AUTHORITY SECTION:
baidu.com.		86400	IN	NS	ns.baidu.com.

;; ADDITIONAL SECTION:
ns.baidu.com.		86400	IN	A	192.168.44.131

;; Query time: 1 msec
;; SERVER: 192.168.44.131#53(192.168.44.131)
;; WHEN: Wed Jan 23 04:02:39 EST 2019
;; MSG SIZE  rcvd: 91

10、反向测试

[root@localhost ~]# dig -x 192.168.44.131
	; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7 <<>> -x 192.168.44.131
	;; global options: +cmd
	;; Got answer:
	;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36048
	;; flags: qr aa rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 2, ADDITIONAL: 3
	;; OPT PSEUDOSECTION:
	; EDNS: version: 0, flags:; udp: 4096
	;; QUESTION SECTION:
	;131.44.168.192.in-addr.arpa.	IN	PTR
	;; ANSWER SECTION:
	131.44.168.192.in-addr.arpa. 86400 IN	PTR	www.baidu.com.44.168.192.in-addr.arpa.
	131.44.168.192.in-addr.arpa. 86400 IN	PTR	ns.qq.com.
	131.44.168.192.in-addr.arpa. 86400 IN	PTR	www.qq.com.
	131.44.168.192.in-addr.arpa. 86400 IN	PTR	ns.baidu.com.
	;; AUTHORITY SECTION:
	44.168.192.in-addr.arpa. 86400	IN	NS	ns.baidu.com.
	44.168.192.in-addr.arpa. 86400	IN	NS	ns.qq.com.
	;; ADDITIONAL SECTION:
	ns.baidu.com.		86400	IN	A	192.168.44.131
	ns.qq.com.		86400	IN	A	192.168.44.131
	;; Query time: 1 msec
	;; SERVER: 192.168.44.131#53(192.168.44.131)
	;; WHEN: Wed Jan 23 04:03:39 EST 2019
	;; MSG SIZE  rcvd: 208
	
[root@localhost ~]# ping 192.168.44.131
PING 192.168.44.131 (192.168.44.131) 56(84) bytes of data.
64 bytes from 192.168.44.131: icmp_seq=1 ttl=64 time=0.050 ms
64 bytes from 192.168.44.131: icmp_seq=2 ttl=64 time=0.027 ms
64 bytes from 192.168.44.131: icmp_seq=3 ttl=64 time=0.028 ms

1.查找方式:

递归——计算机只发送一次请求,服务器会根据提示不断去查找,直到查找到所需
迭代——计算机需要根据提示发送多次请求
ps:实际解析分为两段,一段递归一段迭代

2.解析

正向:FQDN——》IP
反向:IP——》FQDN

3.服务器类型

主DNS服务器:	数据修改 						   master
辅助DNS服务器:  定期请求数据同步    				slave
缓存DNS服务器:   只缓存DNS数据    				hint
转发服务器:		缓存服务器去掉缓存功能   		forward

4.区域类型

主区域:主DNS,master
从区域:从DNS,slave
缓存区域:hint,在找不到相关信息的时候去从根查找,标识根的地址
转发区域:forward,转发到指定区域,而不是指向根

Linux下搭建DNS服务器_第3张图片
5.端口:53

6.资源记录名称

SOA		具体负责哪个区域的解析
NS  	将域名最终映射到哪一台主机(由哪一台主机去解析当前所定义的域主机)
A		正向解析,将主机名映射到ipv4地址
AAAA  	将主机名映射到ipv6地址。  
CNAME  记录域别名
MX 		邮件交换记录
PTR		反向解析,将IPV4 IPV6地址映射到主机名 

7.域名结构

国家顶级,通用顶级,基础结构

关注我的微信公众号:hello521day ,大量网络,渗透、编程资料以及ppt等模板等你来取!

Linux下搭建DNS服务器_第4张图片

你可能感兴趣的:(linux,虚拟机,Linux,服务器,虚拟机,Linux下搭建DNS服务器)