部署DNS域名解析服务器—BIND Server

1、浅谈DNS解析技巧

在搭建服务器以前,咱们须要了解一下DNS域名解析原理,《DNS原理及其解析过程》,整体上,《DNS原理及其解析过程》对解析过程说的很是清楚。html

在这里,补充和强调如下了三点:linux

一、DNS查询:分为递归查询和迭代查询两种
  (1) 递归查询: 即客户端向本地DNS服务器请求查询域名,本地DNS服务器收到查询任务后如自身没法回答则向其余服务器查询,直到查到结果后返回结果给客户端。期间DNS服务器可能要查询不少其余DNS服务器。
(2)迭代查询:即客户端向本地服务器请求查询域名,本地DNS服务器没法回答,则给客户端返回另外一个能查询域名的服务器地址,客户端再向另外一服务器查询,期间可能客户端需查询多个DNS服务器,最终查到结果。

二、DNS服务器分类:

DNS服务器分为:
(1)master(主DNS服务器):拥有区域数据的文件,并对整个区域数据进行管理。
(2)slave(从服务器或叫辅助服务器):拥有主DNS服力器的区域文件的副 本,辅助主DNS服务器对客户端进行解析,当主DNS服务器坏了后,能够彻底接替主服务器的工做。
(3)forward:将任何查询请求都转发给其余服务器。起到一个代理的做用。
(4)cache:缓存服务器。
(4)hint:根DNS internet服务器集。windows

三、DNS劫持缓存

DNS 劫持是网络安全界常见的一个名词,意思是经过某些手段取得某一目标域名的解析记录控制权,进而修改此域名的解析结果,经过此修改将对此域名的访问由原先的 IP地址转入到本身指定的IP,从而实现窃取资料或者破坏原有正常服务的目的。安全

 

2、安装DNS BIND服务器

关于安装DNS服务器,咱们这里使用Windows环境,须要下载Windows版本的Bind服务器服务器

1.下载地址《DNS Bind》,咱们下载相对稳定的版本便可,配置基本相同。网络

2.安装 
将下载的BIND9.9.0.ZIP解压,进入到解压后的文件夹,运行 BINDInstall.exe,在弹出的安装窗口中输入一个密码,一直默认安装就好了,不须要更改什么设置。默认安装到 windows\system32\dns目录下。dom

因为 windows\system32\dns属于系统目录,所以,须要设置各类权限,所以,咱们建议安装到非系统盘,好比(E:/DNSBindServer/),本篇博客的DNS安装位置在(E:/DNSBindServer/)下面分布式

以上帐号,咱们省略,使用系统帐号便可。学习

安装完成以后,咱们打开Windows系统服务管理界面

三、环境配置

3.1首先,创建以下目录环境

3.2生成rndc.key文件

而后CMD窗口,进E:/DNSBindServer/bin目录,用rndc-config.exe程序生产rndc.key。执行以下命令,将在E:/DNSBindServer/etc目录下生成rndc.key

rndc-confgen -a

3.3建立named.conf

在E:/DNSBindServer/etc目录下建立named.conf,这个是Bind服务器默认加载的配置。

配置内容以下

include "E:/DNSBindServer/etc/rndc.key";
controls {
		inet 127.0.0.1 port 953
 		allow { 127.0.0.1; } keys { "rndc-key"; };
 };
 
include "E:/DNSBindServer/etc/named.conf.options";
include "E:/DNSBindServer/etc/named.conf.zones";

第一段引入rndc.key

第二段是控制点,用来远程控制,注意,这楼里的 port:953是控制点端口,不是DNS服务端口,DNS服务端口是53。

第三段是常规配置

 

在E:/DNSBindServer/etc/创建named.conf.options文件,在里面加入以下内容

logging {

channel warning 
{ 
    file "E:/DNSBindServer/log/warning.log" versions 3 size 2048k;
    severity warning;
    print-category yes;
    print-severity yes;
    print-time yes;
};
channel query 
{
    file "E:/DNSBindServer/log/query.log" versions 3 size 2048k;
    severity info;
    print-category yes;
    print-severity yes;
    print-time yes;
};
channel default_syslog { 
    file "E:/DNSBindServer/log/error.log"; 
    severity error; print-category yes;
    print-severity yes;
    print-time yes;
};
channel audit_log { file "E:/DNSBindServer/log/zone_named.log"; severity error; print-time yes; };
    category default { warning;};
    category general { default_syslog; };
    category security { audit_log; default_syslog; };
    category config { default_syslog; };
    category resolver { audit_log; };
    category xfer-in { audit_log; };
    category xfer-out { audit_log; };
    category notify { audit_log; };
    category client { audit_log; };
    category network { audit_log; };
    category update { audit_log; };
    category queries { query; };
    category lame-servers { audit_log; };
};

acl "trust-lan" { 127.0.0.0/8; 192.168.0.0/16; 10.1.0.0/16; }; 
options {
    #域名文件存放的绝对路径
    directory "E:/DNSBindServer/etc/";
    #若是bind启动,自动会在{pid-file}目录生成一个named.pid文件,打开文件就是named进程的ID
    pid-file  "E:/DNSBindServer/log/dns_named.pid";
    version "1.0.0"; 
    allow-transfer { none; }; #容许trust-lan里的IP从主DNS上进行区域传输 
    allow-notify { "trust-lan"; }; #从服务器接收主服务器的更新通知 
    allow-query { "trust-lan"; }; #容许查询,只有trust-lan中的主机发来的DNS请求才会被处理 
    allow-recursion{ none;}; #打开BIND递归查询功能 
    notify yes;
    forwarders {  
        61.234.254.6;
        61.234.254.5;
        59.51.78.211;
        8.8.8.8;
    };

    auth-nxdomain no;    # conform to RFC1035
    #listen-on port 53 { 127.0.0.1;192.168.1.210;10.1.235.92; };
    listen-on-v6 { any; };
};

logging模块是日志通道配置,这对于配置调试很是重要,由于BIND并不自动产生日志,所以,无比在配置阶段添加日志配置,防止配置失败问题产生。特别是以下通道。

category default { warning;};

接下来是

acl "trust-lan" { 127.0.0.0/8; 192.168.0.0/16; 10.1.0.0/16; };

acl(Access Control List)是定义一个常量的声明,用来限制哪些主机的请求被容许响应。

 

下来是很是重要的options配置

options {
    #域名文件存放的绝对路径
    directory "E:/DNSBindServer/etc/";
    #若是bind启动,自动会在{pid-file}目录生成一个named.pid文件,打开文件就是named进程的ID
    pid-file  "E:/DNSBindServer/log/dns_named.pid";
    version "1.0.0"; 
    allow-transfer { none; }; #容许trust-lan里的IP从主DNS上进行区域传输 
    allow-notify { "trust-lan"; }; #从服务器接收主服务器的更新通知 
    allow-query { "trust-lan"; }; #容许普通查询 
    allow-recursion{ none;}; #打开BIND递归查询功能 
    notify yes;
    forwarders {   #若是本地域名没法解析到ip,那么自动前往以下地址
        61.234.254.6;
        61.234.254.5;
        59.51.78.211;
        8.8.8.8;
    };

    auth-nxdomain no;    # conform to RFC1035
    listen-on-v6 { any; };
};

*auth-nxdomain 是否作为权威服务器回答域不存在(Auth-nxdomain)
若是设置为'yes',则容许服务器以权威性(authoritatively)的方式返回NXDOMAIN(该域不存在)的回答,不然就不会做权威性的回答,缺省值为”是”,这里设置为no,让本地服务器到DNS分布式系统去查询。

 

最后建立named.conf.zones文件,输入以下内容

zone  "."  IN  {
    type    hint; #根域名服务器
    file    "E:/DNSBindServer/etc/named.db.root";
};
zone   "localhost"     IN  {
    type    master; #该域名服务器是主域名服务器,这个选项主要用在主备部署中
    file    "E:/DNSBindServer/etc/localhost.zone";
    allow-update    {   none;   };
};

zone    "0.0.127.in-addr.arpa"  IN  { #这种属于反向解析
    type    master;
    file    "E:/DNSBindServer/etc/127.0.0.zone";
    allow-update    {   none;   }; #定义了容许向主zone文件发送动态更新的匹配列表
};

zone    "xushjie.com"   IN  {
    type    master;
    file    "E:/DNSBindServer/etc/xushjie.com.zone";
    allow-update    {   none;   };
};

zone    "0.168.192.in-addr.arpa"     IN  {
    type    master;
    file    "E:/DNSBindServer/etc/192.168.0.zone";
    allow-update    {   none;   };
};
zone "baidu.com"  IN{
    type master;
    file "E:/DNSBindServer/etc/baidu.com.zone";
    allow-update    {   none;   };
};

 

咱们看到,第一项是name.db.root,

下载地址时《ftp://ftp.internic.net/domain/named.root》

 

解析文件配置

反向解析

127.0.0.zone

$TTL  86400
@   IN  SOA     localhost.    root.localhost. (
											    2005030122
											    28800
											    14400
											    3600000
											    86400   )

@   IN  NS  	localhost.
1   IN  PTR     localhost.  ;反解析,注意,1表示主机号,者此处是 127.0.0.1 
2   IN  PTR     localhost.  ;反解析,注意,2表示主机号,者此处是 127.0.0.2

192.168.0.zone

$TTL 86400
@   IN  SOA     ns.xushjie.com.    root.xushjie.com. (  ;ns.xushjie.com.表示域名组, root.xushjie.com.表示邮箱root@xueshjie.com
												    2005030119
												    7200
												    3600
												    43200
												    86400   )

@   IN  NS      ns.xushjie.com.  ;反向解析第一句表示类型(必须)
1 	IN  PTR     www.xushjie.com. ;表示192.168.0.1
100 IN  PTR     www.xushjie.com.  ;表示192.168.0.100

正向解析

localhost.zone

$TTL    86400
localhost.    IN    SOA    localhost.    root.localhost.    (
                                 2001062501   ;serial 
                                 21600        ;refresh
                                 3600		  ;retry
                                 604800       ;expire
                                 86400        ;mininum
                                 )
@    IN       NS    localhost.
@    IN    	  A     127.0.0.1
@    IN 	  AAAA  ::1

xushijie.com.zone

$TTL    86400
@   IN  SOA     ns.xushjie.com.    root.xushjie.com. ( 
                                 1053891168
                                 21600
                                 3600
                                 604800
                                 86400 )

@    IN    NS   ns.xushjie.com.
ns   IN    A    192.168.0.100
www  IN    A    192.168.0.100

其中一句以下:用来表示域名所对应的地址组(ns.xushjie.com),以及管理员邮箱(root.xushjie.com.,本应该是root@xushjie.com,可是@具备特殊意义)

@   IN  SOA     ns.xushjie.com.    root.xushjie.com.

再来看下个例子

baidu.com.zone

$TTL 86400
@ IN SOA ns1.baidu.com. root.baidu.com.(
	 							 2001072501   ;serial 
                                 21600        ;refresh
                                 3600		  ;retry
                                 604800       ;expire
                                 86400        ;mininum
)
@ 		IN    NS  	ns1.baidu.com.   ;(定义ns1)
ns1   	IN    A    	220.181.112.244  ;(让ns1指向对应的ip,不然如下地址没法解析)
www  	IN    A    	220.181.112.244
image 	IN    A 	180.149.131.70

 

关于配置,请参考以下博客

[DNS] BIND9详解 BIND9配置方法

DNS开源服务器BIND最小配置详解

DNS named.conf配置&DNS主从配置》

《 DNS与BIND学习笔记-基础知识及配置详解 》

DNS服务器bind的master 和 slave 搭建

DNS unix环境搭建

DNS服务器之一:DNS简介及BIND安装与基本配置 系列文章》

DNS扫盲系列之五:域名配置ZONE文件 系列文章》

4.接下来就是DNS 测试

首先要启动BindServer

而后执行以下命令

目前为止,咱们的DNS服务器已经安装完成。

 

5.私有解析服务器设置

可是,这DNS服务器是独立运行的,若是咱们直接执行以下命令

dig www.baidu.com

那么不会经过BINDServer解析,所以,为了进一步使用BINDServer,咱们须要设置主机DNS服务地址

相关文章
相关标签/搜索