bind for Windows的安装、配置和运行
WMProject1217
编辑于 2023年07月18日 19:58

bind for Windows的安装、配置和运行

用过Windows DNS服务器的都知道Windows DNS服务器占用较多RAM,且功能比bind少得多。

某些时候,我们必须在Windows系统上配置DNS服务器,此时选择bind for Windows是建议的。

安装、配置和运行bind for Windows

首先打开ftp://ftp.isc.org/isc/bind9/,从中找一个比较新的版本文件夹打开,此处选择的是9.17.9版本。

下载其中的BIND9.17.9.x64.zip。

使用你最喜欢的压缩文件管理器打开此文件,你会看到其中包含以下内容。

其中BINDInstall.exe是自带的安装程序,但是由于各种原因,本教程不会使用此程序。

在你喜欢的,不包含特殊字符的目录里创建bind文件夹,此处使用的是X:\WMSystem\lib\,然后在其中创建bin和etc文件夹。

将BIND9.17.9.x64.zip像这样完全解压到bind\bin文件夹中。

打开注册表编辑器,切换到到HKEY_LOCAL_MACHINE\SOFTWARE\ISC\BIND(没有就创建),创建字段InstallDir,数据为你bind目录的位置,此处为X:\WMSystem\lib\bind。

然后打开bind\etc文件夹,新建文本文档,然后重命名为named.conf。

使用Visual Studio Code/Visual Studio Codium/Atom/vim/nano或者其他任何可以编辑UTF-8文本文档而不会留下BOM头的文本编辑器打开named.conf,然后写入以下内容。

 

options {

    # 你的bind\etc文件夹完整路径

    directory "X:\WMSystem\lib\bind\etc&#​34;;

 

    # 如果bind无法解析,会向以下DNS服务器发送查询请求。

    # 可以在下面的IP地址位置上填写ISP的DNS地址。

    forwarders {

        10.1.1.1;

        10.0.1.1;

        8.8.8.8;

        8.8.4.4;

    };

 

    # 允许哪些IP查询。

    # 此处允许了本机和一个A类局域网,如果你要在C类局域网上使用,添加的内容可能为192.168.1.0/24;。

    allow-query {

        127.0.0.1;

        10.0.0.0/8;

    };

};

 

# 根DNS

zone ".&#​34; {

    type hint;

    file "named.root&#​34;;

};

 

# localhost

zone "localhost&#​34; IN {

    type master;

    file "localhost.zone&#​34;;

    allow-update { none; };

};

 

# localhost的反向解析

zone "0.0.127.in-addr.arpa&#​34; {

    type master;

    file "localhost.rev&#​34;;

};

 

# example.com

zone "example.com&#​34; IN {

    type master;

    file "example.com.zone&#​34;;

};

 

就像Linux上的bind一样,此处指定了一些域的zone文件和反向解析的rev文件,应该在bind\etc下创建这些文件。

此处文件内容如下。

 

## example.com.zone

$TTL 1D

 

@       IN      SOA     example.com.      root. example.com. (

        2007091701          ; Serial

        30800               ; Refresh

        7200                ; Retry

        604800              ; Expire

        300 )               ; Minimum

 

        IN      NS      example.com.

 

example.com.        IN      A       10.0.10.10

www.example.com.        IN      A       10.0.10.10

*       IN    A         10.0.10.10

 

## localhost.zone

$TTL 1D

 

@       IN      SOA     localhost.      root.localhost. (

        2007091701          ; Serial

        30800               ; Refresh

        7200                ; Retry

        604800              ; Expire

        300 )               ; Minimum

 

        IN      NS      localhost.

 

localhost.        IN      A       127.0.0.1

 

## localhost.rev

$TTL    1D

 

@       IN      SOA    localhost.    root.localhost. (

        2007091701          ; Serial

        30800               ; Refresh

        7200                ; Retry

        604800              ; Expire

        300 )               ; Minimum

 

            IN      NS      localhost.

1           IN      PTR     localhost.

 

## named.root

.                    480717    IN    NS   d.root-servers.net.

.                    480717    IN    NS   b.root-servers.net.

.                    480717    IN    NS   l.root-servers.net.

.                    480717    IN    NS   k.root-servers.net.

.                    480717    IN    NS   f.root-servers.net.

.                    480717    IN    NS   h.root-servers.net.

.                    480717    IN    NS   m.root-servers.net.

.                    480717    IN    NS   c.root-servers.net.

.                    480717    IN    NS   a.root-servers.net.

.                    480717    IN    NS   g.root-servers.net.

.                    480717    IN    NS   i.root-servers.net.

.                    480717    IN    NS   e.root-servers.net.

.                    480717    IN    NS   j.root-servers.net.

 

然后回到bind\bin,新建文本文档,然后重命名为start.cmd,用记事本打开,写入以下内容。

cd /d %~dp0

named -f -g -d 1

pause

用管理员权限执行此脚本,等待一段时间后,你将看到以下窗口,这说明bind已经启动。

如果需要停止bind,仅需关闭这个命令行窗口。

其它

配置rndc

按下Windows+X,然后按下A,使用管理员权限打开cmd,并 cd /d 到bind\bin目录。

输入rndc-confgen –a,按下Enter。

输入rndc-confgen > rndc.conf,按下Enter。

执行后应存在bind\etc\rndc.key和bind\bin\rndc.conf这两个文件。

如果不存在,请在网络上搜索错误代码,依照网络上的教程来试图处理此错误。

named.root的生成

其实named.root可以自动生成,这要求本地计算机网络畅通。

按下Windows+X,然后按下A,使用管理员权限打开cmd,并 cd /d 到bind\bin目录。

输入dig > ../etc/named.root,按下Enter。

执行后应存在bind\etc\named.root。

报错

按照本文的"安装、配置和运行bind for Windows&#​34;节来检查,如果没有问题,请按以下步骤修改文件夹安全设置。

右键文件夹属性,切换到"安全&#​34;选项卡,单击"高级&#​34;。

单击"所有者&#​34;旁边的更改按钮,输入Everyone,按下确定。

选中"替换子容器和对象的所有者&#​34;。

单击窗口下半部分的"禁用继承&#​34;按钮,选择"从此对象中删除所有已继承的权限&#​34;。

单击"添加&#​34;,选择主体,输入Everyone,确定。

在基本权限中勾选完全控制。

勾选"使用可从此对象继承的权限项目替换所有子对象的权限项目&#​34;,按下确定。

出现的所有提示框都按"是&#​34;。

此时权限已经被更新。

如果仍然报错,请在网络上搜索错误代码,依照网络上的教程来试图处理此错误。