Chinaunix首页 | 论坛 | 博客
  • 博客访问: 610917
  • 博文数量: 244
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-27 09:53
个人简介

记录学习,记录成长

文章分类

全部博文(244)

我的朋友

分类: LINUX

2015-08-02 18:08:46

1.rndc命令解析:
rndc是BIND安装包提供的一种控制域名服务运行的工具,它可以运行在其他计算机上,通过网络与DNS服务器进行连接,然后根据管理员的指令对named进程进行远程控制,此时,管理员不需要DNS服务器的根用户权限。使用rndc可以在不停止DNS服务器工作的情况进行数据的更新,使修改后的配置文件生效而且rndc与DNS服务器实行连接时,需要通过数字证书进行认证,而不是传统的用户名/密码方式,rndc在连接通道中发送命令时,必须使用经过服务器认可的密钥加密。为了生成双方都认可的密钥,可以使用rndc-confgen命令产生密钥和相应的配置,再把这些配置分别放入named.conf和rndc的配置文件rndc.conf中

rndc命令选项参数:
rndc     [-b source-address]     [-c config-file]     [-k key-file]     [-s server]     [-p port]     [-V]     [-y key_id]     {command}
参数:
-b source-address     #使用 source-address 作为连接服务器的源地址。允许多个实例设置 IPv4 和 IPv6 源地址
-c config-file             #使用config-file 作为缺省的配置文件/etc/rndc.conf 的替代。
-k key-file                 #使用 key-file 作为缺省的密钥文件/etc/rndc.key 的替代。如果config-file 不存在,/etc/rndc.key 中的密钥将用于认证发向服务器的命令。
-s server server         #是与 rndc 的配置文件中 server语句匹配的服务器的名字或地址。如果命令行没有提供服务器,会使用 rndc 配置文件中 options 语句中的 default-server子句所命名的主机。
-p port                     #发送命令到 TCP端口 port,以取代 BIND 9 的缺省控制通道端口 953。
-V                           #打开冗余日志。
-y key_id                 #使用配置文件中的密钥 key_id
command参数:

reload                                     重新装入配置文件和区域
reload zone [class [view]]         重新装入单个区域
refresh zone [class [view]]        安排区域的立即维护
reconfig                                  仅重新装入配置文件和新区域
stats                                       将服务器统计信息写入统计文件中
querylog                                 切换查询日志
dumpdb                                 将高速缓存转储到转储文件 (named_dump.db)
stop                                       将暂挂更新保存到主文件并停止服务器
halt                                        停止服务器,但不保存暂挂更新
trace                                      将调试级别增加一级
trace level                               更改调试级别
notrace                                   将调试级别设置为 0
flush                                      刷新服务器的所有高速缓存
flush [view]                            为某一视图刷新服务器的高速缓存
status                                     显示服务器的状态
*restart                                  重新启动服务器(暂不能实现)

2.在同一台主机(192.168.85.128)上测试rndc
2.1  使用rndc-confgen  >  /etc/rndc.conf命令生成配置文件
[root@localhost ~]# rndc-confgen > /etc/rndc.conf
[root@localhost ~]# cat /etc/rndc.conf 
# Start of rndc.conf        #配置文件的内容
key "rndc-key" {
        algorithm hmac-md5;
        secret "PVxyBkLAK+edj/3tEuckJg==";
};
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:        #把这些内容加到named.conf中
# key "rndc-key" {
#       algorithm hmac-md5;
#       secret "PVxyBkLAK+edj/3tEuckJg==";
# };

# controls {
#       inet 127.0.0.1 port 953
#               allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf
注意:这里我在SecureCRT软件中输入rndc-confgen一直无法显示,但是在虚拟机里的终端中却一下子就好了,查了一下,别人也碰到过这种情况,我也不清楚原理,查到有一种方法可以,不过我没试,把这种方法复制下来:
rndc-confgen 调用 /dev/random ,而 /dev/random 又通过 /proc/interrupts 产生随机数不足,导致
rndc-confgen 一直等待
rndc-confgen --help 可以指定 randomfile
1.
手动生成一个 randomfile 文件
# echo "selbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselbooselboo" > test
# rndc-confgen -r test 
2.
rndc-confgen -r /dev/urandom
/dev/random 和 /dev/urandom 详解

2.2  下面就是把rndc.conf中的后半部分注释内容加到named.conf中并去掉注释生效
# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndc-key" {            #将鼠标移动到此行
#       algorithm hmac-md5;
#       secret "PVxyBkLAK+edj/3tEuckJg==";
# };
#
# controls {
#       inet 127.0.0.1 port 953
#               allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf
:.,$-1w >> /etc/named.conf        #功能是将当前行到倒数第二行(包括)的内容追加到named.conf中
编译/etc/named.conf文件
# key "rndc-key" {        #鼠标移动到此行
#       algorithm hmac-md5;
#       secret "PVxyBkLAK+edj/3tEuckJg==";
# };
#
# controls {
#       inet 127.0.0.1 port 953
#               allow { 127.0.0.1; } keys { "rndc-key"; };
# };
:.,$s/^# //g              #功能是将从当前行到最后一行以#开头且紧跟着一个空格的字符替换为空格
确定保存退出即可

2.3  测试
先重启服务在测试否则会出现错误:
[root@localhost ~]# service named restart
Stopping named: .[  OK  ]
Starting named: [  OK  ]
[root@localhost ~]# rndc -c /etc/rndc.conf status
version: 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3        #版本号  
CPUs found: 1                           #主机上cpu个数
worker threads: 1                      #named工作进程个数
number of zones: 20                  
debug level: 0
xfers running: 0                          #是否有区域传送
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/0/1000
tcp clients: 0/100
server is up and running               #服务状态
错误如下:
[root@localhost ~]# rndc -c /etc/rndc.conf status
rndc: connection to remote host closed
This may indicate that
* the remote server is using an older version of the command protocol,
* this host is not authorized to connect,
* the clocks are not synchronized, or
* the key is invalid.

或者
[root@localhost ~]# rndc -c /etc/rndc.conf stop
[root@localhost ~]# service named status
WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf)
rndc: connect failed: 127.0.0.1#953: connection refused
named dead but subsys locked
[root@localhost ~]# netstat -untlp | grep 53
[root@localhost ~]# service named start
Starting named: [  OK  ]

3.测试在192.168.85.133上控制192.168.85.128上的DNS服务                
3.1  修改192.168.85.128上的/etc/named.conf文件
controls {
        inet 192.168.85.128  port 953        #在本机运行一个rndc监听端口953来监听主机192.168.85.128
                allow { 192.168.85.133; } keys { "rndc-key"; };        #允许192.168.85.133主机使用rndc-key来控制
};
保存退出并重启服务
此时的监听情况
[root@localhost ~]# netstat -antlp | grep named
tcp        0      0 192.168.85.128:53           0.0.0.0:*                   LISTEN      4732/named          
tcp        0      0 127.0.0.1:53                0.0.0.0:*                   LISTEN      4732/named          
tcp        0      0 192.168.85.128:953          0.0.0.0:*                   LISTEN      4732/nam
此时远程主机192.168.85.133可以通过953端口连接该主机但是还没有密钥
3.2  将本地主机的/etc/rndc.conf发送到远程主机上(如果远程主机上的/etc中已有该文件时就换个目录存放以免文件覆盖)
[root@localhost ~]# scp /etc/rndc.conf 192.168.85.133:/root/
The authenticity of host '192.168.85.133 (192.168.85.133)' can't be established.
RSA key fingerprint is e5:5e:5f:35:39:f9:71:f0:80:7b:60:a6:83:eb:7c:aa.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.85.133' (RSA) to the list of known hosts.
root@192.168.85.133's password: 
rndc.conf                                                                   100%  479     0.5KB/s   00:00    

3.3  在远程主机133上查看并修改文件
[root@localhost ~]# ls /root/ | grep rndc
rndc.conf

key "rndc-key" {
        algorithm hmac-md5;
        secret "PVxyBkLAK+edj/3tEuckJg==";
};
options {
        default-key "rndc-key";
        default-server 192.168.85.128;    
        default-port 953;
};

3.4  测试远程主机133控制本地服务器128
[root@localhost ~]# rndc -c rndc.conf status    #注意此时的路径
version: 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.3
CPUs found: 1
worker threads: 1
number of zones: 20
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/0/1000
tcp clients: 0/100
server is up and running



阅读(3519) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~