「Bind」- 使用RNDC管理服务

内容简介

在Bind中,可以使用内置的rndc(8)命令管理Bind服务。比如:rndc status,查看服务的状态;rndc trace,将调试级别加一;等等。

本文将介绍在BIND中配置及使用RNDC管理工具。

RNDC – name server control utility

RNDC,用于操作域名服务,对应sbin/rndc命令,使用TCP连接与域名服务通信,使用953端口,使用数字签名进行身份验证。

附加说明

如果是直接从源中安装DNS服务,则RNDC一般不需要单独配置。使用ss -n -o state listening sport = 953验证服务是否开启管理

配置RNDC管理

#1 生成rndc.conf配置文件

执行rndc-confgen命令生成配置文件:

#!/bin/sh

rndc-confgen -r /dev/urandom > etc/rndc.conf

# 在多数情况下,配置文件rndc.conf与named.conf位于同级目录中。

由上述命令生成的rndc.conf文件内容如下:

# Start of rndc.conf
key "rndc-key" {
        algorithm hmac-md5;
        secret "utSg/xHrAYorbcG6eJIT4Q==";
};

options {
        default-key "rndc-key";
        default-server 127.0.0.1;
        default-port 953;
};
# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndc-key" {
#       algorithm hmac-md5;
#       secret "utSg/xHrAYorbcG6eJIT4Q==";
# };
#
# controls {
#       inet 127.0.0.1 port 953
#               allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf

#2 修改named.conf配置文件

正如上面生成的配置文件中所述,将注释部分复制到named.conf即可:

# ……(省略named.conf中其他配置)

# Use with the following in named.conf, adjusting the allow list as needed:
key "rndc-key" {
      algorithm hmac-md5;
      secret "utSg/xHrAYorbcG6eJIT4Q==";
};

controls {
      inet 127.0.0.1 port 953
              allow { 127.0.0.1; } keys { "rndc-key"; };
};
# End of named.conf

#3 重启named服务

安装方式不同,启动方式不同,则重启方式也不同:

#!/bin/sh

# CentOS 7
systemctl restart named.service

#4 验证

执行如下命令,验证rndc是否能够正确连接服务:

#!/bin/sh

rndc status

由上述命令产生输出内容,类似如下所示:

version: BIND 9.11.0-P1 <id:1e9bd53>
running on dns: Linux x86_64 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017
boot time: Fri, 30 Aug 2019 08:20:50 GMT
last configured: Fri, 30 Aug 2019 08:20:50 GMT
configuration file: /usr/local/bind/etc/named.conf
CPUs found: 2
worker threads: 2
UDP listeners per interface: 1
number of zones: 297 (294 automatic)
debug level: 1
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/900/1000
tcp clients: 0/150
server is up and running

附加说明

在配置rndc之后,如果修改了配置文件或者区域文件,可以执行rndc reload命令重新加载配置文件与区域文件。

如果rndc命令无法连接域名服务,可能是因为配置文件rndc.conf的路径不对,导致rndc命令没有找到rndc.conf文件。

参考文献

Configure RNDC Key for Bind9 ( DNS Server )
10 examples of Linux ss command to monitor network connections
include Statement Grammar
options Statement Grammar