为Bind9 (DNS服务器)配置RNDC密钥

时间:2019-05-19 01:25:44  来源:igfitidea点击:

RNDC控制name服务器的操作。
rndc使用tcp连接与bind server通信,以发送经过数字签名验证的命令。
使用以下步骤为Bind9配置 RNDC键。

步骤1:创建RNDC密钥和配置文件

第一步是创建 rndc key文件和配置文件。
rndc提供命令行工具rndc-confgen来生成它。

# rndc-confgen

输出示例:

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

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 "DTngw5O8I5Axx631GjQ9pA==";
# };
#
# controls {
#       inet 127.0.0.1 port 953
#               allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf

步骤2:配置RNDC密钥和配置文件

2.1将步骤1的全部输出内容复制到/etc/rnd.conf。
2.2将步骤1的key部分复制到/etc/rndc.key文件。

# cat /etc/rndc.key

key "rndc-key" {
        algorithm hmac-md5;
        secret "DTngw5O8I5Axx631GjQ9pA==";
};

第3步:配置named.conf以使用rndc密钥

在named.conf中添加下面的条目。
我已经添加到上面的选项的部分。

include "/etc/rndc.key";

controls {
        inet 127.0.0.1 allow { localhost; } keys { "rndc-key"; };
};

步骤4:重新启动绑定服务

在重新启动绑定服务之前,我建议先检查配置文件。

# named-checkconf /etc/named.conf
and
# named-checkconf -t /var/named/chroot /etc/named.conf

如果上面的命令在输出中没有显示任何内容,说明配置已经完成,现在重新启动bind service。

# /etc/init.d/named restart

第6步:测试RNDC设置

使用rndc命令测试设置,如下所示。

# rndc status