Ubuntu搭建DNS服务器

这里只是初步介绍搭建方法,经过本地测试和客户端测试可以顺利查询其他网站(准确说,写这篇文章时,我就是通过目前搭建的DNS服务器中转DNS查询)。
首先是实验环境
使用VMware虚拟机和Ubuntu18.04系统建立虚拟机,作为server,网络连接方式使用桥接模式。

然后是下载bind9
使用指令sudo apt install bind9
在这里插入图片描述
bind9安装在/etc/bind位置,进入该文件夹,可以查看文件权限
在这里插入图片描述
这里首先看到named.conf,named.conf.local,named.conf.options三个文件,首先我们查看named.conf
在这里插入图片描述
可以发现里面是引用了named.conf.options, named.conf.local, named.conf.default-zones 三个文件,下面我们DNS服务器的配置主要在这些文件内进行。
首先是配置named.conf.local文件

//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "test.cn"{
        type master;
        file "/etc/bind/db.test.cn";
};

zone "206.168.192.in-addr.arpa"{
        type master;
        file "/etc/bind/db.192.example.com";
};

这里分别给出了自定义域名及其ip地址,然后具体的正向查询和反向查询的配置文件在file 内

这里给出两个配置文件。
/etc/bind/db.test.cn

$TTL 604800
$ORIGIN test.cn.
@ IN SOA test.cn. root.test.cn. (
2006080401 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1
@ IN A 192.168.206.130
ns1 IN A 192.168.206.130
www IN A 192.168.206.130                

/etc/bind/db.192.example.com

$TTL 604800
@       IN       SOA     test.cn. root.test.cn. (
        20211201;Serial
        604800  ;Refresh
        86400   ;Retry
        2419200 ;Expire
        604800) ;Negative Cache TTL
;
@       IN      NS      test.cn.
130     IN      PTR     www.test.cn.
130     IN      PTR     nsl.test.cn.
~                                            

最后需要配置一下named.conf.options文件

options {
        directory "/var/cache/bind";

        // If there is a firewall between you and nameservers you want
        // to talk to, you may need to fix the firewall to allow multiple
        // ports to talk.  See http://www.kb.cert.org/vuls/id/800113

        /// If your ISP provided one or more IP addresses for stable
        // nameservers, you probably want to use them as forwarders.
        // Uncomment the following block, and insert the addresses replacing
        // the all-0's placeholder.

        forwarders {
                8.8.8.8;
        };

        //========================================================================
        // If BIND logs error messages about the root key being expired,
        // you will need to update your keys.  See https://www.isc.org/bind-keys
        //========================================================================
        dnssec-validation auto;

        auth-nxdomain no;    # conform to RFC1035
        listen-on-v6 { any; };
        listen-on port 53 {192.168.75.129;}; //这一项是填写自己的DNS服务器IP地址
		allow-transfer {any; };
		allow-query{ any; };
  };

这样最基础的就配置完成了,同时,forward后面跟的域名是在无法查到域名IP时,转发向的公共DNS服务器IP
下面是进行的测试
首先启动bind9
在这里插入图片描述
进行本地查询
在这里插入图片描述

然后在另一台机器上将DNS服务器指向该虚拟机IP
然后使用python进行查询
在这里插入图片描述

问题记录
1、启动bind9之后,无法查询到配置的A记录。

对于该问题,我进行了以下几步尝试。
首先是查看启动日志文献 tail /var/log/syslog
在bind配置没用问题的情况下,输出应当型如下方所示:

Mar 19 22:43:14 ubuntu named[61378]: managed-keys-zone: loaded serial 3

Mar 19 22:43:14 ubuntu named[61378]: zone 0.in-addr.arpa/IN: loaded serial 1

Mar 19 22:43:14 ubuntu named[61378]: zone 255.in-addr.arpa/IN: loaded serial 1

Mar 19 22:43:14 ubuntu named[61378]: zone 127.in-addr.arpa/IN: loaded serial 1

Mar 19 22:43:14 ubuntu named[61378]: zone localhost/IN: loaded serial 2

Mar 19 22:43:14 ubuntu named[61378]: zone smart-clouds.cn/IN: loaded serial 2006080401

Mar 19 22:43:14 ubuntu named[61378]: all zones loaded

Mar 19 22:43:14 ubuntu named[61378]: running

Mar 19 22:43:14 ubuntu named[61378]: zone smart-clouds.cn/IN: sending notifies (serial 2006080401)

在检查完启动项,确定配置无问题之后,再次尝试查询,如果还没有的话,问题可能是出在虚拟机默认的DNS服务器上。我这边是将/etc/resolv.conf的内容全部删除。原因是该文件内配置的DNS服务器优先级要高于bind中配置的服务器。

参考文献
Ubuntu采用bind9配置DNS服务器
Ubuntu下搭建DNS服务器
Ubuntu下DNS服务器的配置

  • 8
    点赞
  • 87
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供大致的步骤。具体细节因环境不同而异,请您根据自己的实际情况适当调整。 1. 安装 DNS 服务器Ubuntu 上安装 DNS 服务器可以使用 BIND9 工具,可以使用以下命令进行安装: ``` sudo apt-get update sudo apt-get install bind9 ``` 2. 配置正向解析 正向解析是指将域名解析为 IP 地址,可以通过以下步骤进行配置: - 编辑 /etc/bind/named.conf.local 文件,添加以下内容: ``` zone "example.com" { type master; file "/etc/bind/db.example.com"; }; ``` - 创建 /etc/bind/db.example.com 文件,添加以下内容: ``` $TTL 604800 @ IN SOA ns1.example.com. admin.example.com. ( 3 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. @ IN A 192.168.0.100 ``` 其中,example.com 是您的域名,192.168.0.100 是您的 IP 地址,可以根据实际情况进行修改。 - 重启 BIND9 服务: ``` sudo systemctl restart bind9 ``` 3. 配置反向解析 反向解析是指将 IP 地址解析为域名,可以通过以下步骤进行配置: - 编辑 /etc/bind/named.conf.local 文件,添加以下内容: ``` zone "0.168.192.in-addr.arpa" { type master; file "/etc/bind/db.192"; }; ``` - 创建 /etc/bind/db.192 文件,添加以下内容: ``` $TTL 604800 @ IN SOA ns1.example.com. admin.example.com. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. 100 IN PTR example.com. ``` 其中,example.com 是您的域名,100 是您的 IP 地址的最后一段数字,可以根据实际情况进行修改。 - 重启 BIND9 服务: ``` sudo systemctl restart bind9 ``` 完成以上步骤后,您的 DNS 服务器就可以进行正反向解析了。您可以通过在其他主机上配置 DNS 服务器为您的 Ubuntu 服务器的 IP 地址,然后在命令行中使用 nslookup 命令进行测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值