Ubuntu使用bind9配置DNS服务器

        为了实现负载均衡,扩展服务器带宽,需要自己配置DNS服务器解析对应域名。

        本文记录Ubuntu系统配置DNS服务的方法。

        假设域名www.mydomain.com 已在阿里云作了解析,现在需要新增一个二级域名 stream.mydomain.com 做推流服务,需要使用自己配置的DNS服务做请求解析分发。

1、安装bind9

        使用指令安装DNS服务程序bind9

apt-get install bind9

2、修改option配置文件

        option配置文件路径为 /etc/bind/named.conf.options, 去掉文件中forwarders的注释。forwarders节点配置的是转发器,所有非本域的和在缓存中无法找到的域名查询都将转发到设置的DNS转发器上,由这台DNS来完成解析工作并做缓存。转发器设置两个常用的DNS服务器即可:

forwrders{
    8.8.8.8;
    114.114.114.114;
}

        完整的option文件:

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;
                114.114.114.114;
         };

        //========================================================================
        // 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 { any; };
        listen-on-v6 { any; };
};

3、修改本地解析目录文件

        修改本地解析目录文件,添加解析域名。修改文件:/etc/bind/named.conf.local,添加新的解析区域节点:

zone "mydomain.com" {   //解析区域名称
        type master;
        file "/etc/bind/db.mydomain.com";   //解析区域对应的配置文件
};

4、添加解析区域配置文件

        使用cp命令复制一份默认localhost区域的配置文件进行新的区域配置的修改:

cp /etc/bind/db.local /etc/bind/db.mydomain.com

        区域配置文件db.mydomain.com完整配置:

;

;
$TTL    604800
@       IN      SOA     mydomain.com.  root.mydomain.com. (
                        2022031012      ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.
;
stream  IN      A       192.168.55.36
stream  IN      A       192.168.55.39
;
;

        SOA记录:起始授权记录 Start of Authority record 宣告了namespace使用哪个nameserver的权威信息。须位于指令后第一行,是区域文件的第一个资源记录。格式如下:

@  IN  SOA  primary-name-server hostmaster-email (
       serial-number
       time-to-refresh
       time-to-retry
       time-to-expire
       minimum-TTL )

@ 表示使用域名作为这个 SOA 的 namespace。

        primary-name-server:该域权威DNS的主名称服务器的主机名

        hostmaster-email:该namespace联系人邮件

        serial-number:序列号,每次此区域文件被修改后,该序列号应该增加,以此提醒域名服务要重新加载该区域了。

        NS记录: 名称服务器记录指定了权威名称服务器。格式如下:

IN NS nameserver-name   ;nameserver-name 应该是完全域名(FQDN)。

        每个区域配置文件都必须包含至少一个NS记录。

        A 记录:给名称指定解析地址。格式如下:

hostname IN A IP-address

5、服务管理指令

        同样,如非必要可以不用添加反向解析设置。

        配置文件都修改保存后,重启服务,进行检验测试

systemctl stop bind9.service //停止服务
systemctl restart bind9.service //重启服务
systemctl reload bind9.service  //重新加载配置
systemctl status bind9.service  //服务状态查询

        进行状态查询时,如果配置的部分地址不可访问,可能会有警告提示:

root@iZwz924eh34ene3sxg0an3Z:/etc/bind# systemctl status bind9.service 
鈼[0m bind9.service - BIND Domain Name Server
   Loaded: loaded (/lib/systemd/system/bind9.service; enabled; vendor preset: enabled)
  Drop-In: /run/systemd/generator/bind9.service.d
           鈹斺攢50-insserv.conf-$named.conf
   Active: active (running) since Thu 2022-03-10 10:33:49 CST; 4 days ago
     Docs: man:named(8)
 Main PID: 32731 (named)
   CGroup: /system.slice/bind9.service
           鈹斺攢32731 /usr/sbin/named -f -u bind

Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: no valid RRSIG resolving './NS/IN': 198.97.190.53#53
Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: network unreachable resolving './NS/IN': 2001:500:3::42#53
Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: network unreachable resolving './NS/IN': 2001:500:84::b#53
Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: network unreachable resolving './NS/IN': 2001:7fd::1#53
Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: validating ./NS: no valid signature found
Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: no valid RRSIG resolving './NS/IN': 202.12.27.33#53
Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: network unreachable resolving './NS/IN': 2001:dc3::35#53
Mar 14 11:33:57 iZwz924eh34ene3sxg0an3Z named[32731]: network unreachable resolving './NS/IN': 2001:500:2::c#53
Mar 14 11:33:58 iZwz924eh34ene3sxg0an3Z named[32731]: validating ./NS: no valid signature found
Mar 14 11:33:58 iZwz924eh34ene3sxg0an3Z named[32731]: no valid RRSIG resolving './NS/IN': 199.7.83.42#53
root@iZwz924eh34ene3sxg0an3Z:/etc/bind# 

        比如上面示例的 NS 记录配置的 ns. 就是不能访问的,随便写的。所以有很多报错信息。但是也不影响 stream.mydomain.com的解析。

        可以直接使用 nslookup 或者 dig 进行解析测试。

        需要记住的是每次修改区域配置文件,都要修改SOA记录中的序列号。公网DNS服务器更新本地修改需要时间,10分钟左右不等。经测试8.8.8.8更新要比114.114.114.114更快。

  • 3
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
root@6527d9173397:/# apt update Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease Err:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Temporary failure resolving 'security.ubuntu.com' Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Err:1 http://archive.ubuntu.com/ubuntu jammy InRelease Temporary failure resolving 'archive.ubuntu.com' Err:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Temporary failure resolving 'archive.ubuntu.com' Err:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Temporary failure resolving 'archive.ubuntu.com' Reading package lists... Done Building dependency tree... Done Reading state information... Done All packages are up to date. W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease Temporary failure resolving 'security.ubuntu.com' W: Some index files failed to download. They have been ignored, or old ones used instead.
06-12

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_老杨_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值