dc: connect failed: connection refused
rndc: connect failed: connection refused

解决办法:
默认安装BIND9以后,是无法直接使用 ndc 或 rndc 命令的。

先重新生成 rndc.conf
rndc-confgen > /etc/rndc.conf

 rndc.conf 下面注释部分 Copy 到 /etc/rndc.key 文件中(必须将前面的#去掉)。

如:
# key "rndc-key" {
# algorithm hmac-md5;
# secret "xbPNyGOcwJp8pEJDLo26cQ==";
# };
#
# controls {
# inet 127.0.0.1 port 953
# allow { 127.0.0.1; } keys { "rndc-key"; };
# };

如果 /etc/named.conf 中包含有 controls 这一Section,先注释掉

然后在后面添加一行 include "/etc/rndc.key";

这样做是为了安全考虑,否则可以直接copy到 named.conf 文件中。

inet / port 的意思是,在 本机运行一个 rndc 监听端口 ,允许本机执行 ndc 或 rndc 命令。

[root@example etc]# named -g
12-May-2010 11:15:03.197 starting BIND 9.3.6-P1-RedHat-9.3.6-4.P1.el5 -g
12-May-2010 11:15:03.211 adjusted limit on open files from 4096 to 1048576
12-May-2010 11:15:03.211 found 1 CPU, using 1 worker thread
12-May-2010 11:15:03.212 using up to 4096 sockets
12-May-2010 11:15:03.266 loading configuration from '/etc/named.conf'
12-May-2010 11:15:03.270 using default UDP/IPv4 port range: [1024, 65535]
12-May-2010 11:15:03.271 using default UDP/IPv6 port range: [1024, 65535]
12-May-2010 11:15:03.288 listening on IPv4 interface lo, 127.0.0.1#53
12-May-2010 11:15:03.311 listening on IPv4 interface eth1, 192.168.1.108#53
12-May-2010 11:15:03.312 listening on IPv4 interface vmnet1, 192.168.157.1#53
12-May-2010 11:15:03.313 listening on IPv4 interface vmnet8, 172.16.237.1#53
12-May-2010 11:15:03.336 listening on IPv4 interface virbr0, 192.168.122.1#53
12-May-2010 11:15:03.337 binding TCP socket: address in use
12-May-2010 11:15:03.395 command channel listening on 127.0.0.1#953
12-May-2010 11:15:03.396 ignoring config file logging statement due to -g option
12-May-2010 11:15:03.396 couldn't open pid file '/var/run/named/named.pid': Permission denied

[root@example etc]# chmod 777 /var/run/named/
[root@example etc]# named -g
12-May-2010 11:24:08.058 starting BIND 9.3.6-P1-RedHat-9.3.6-4.P1.el5 -g
12-May-2010 11:24:08.059 adjusted limit on open files from 4096 to 1048576
12-May-2010 11:24:08.059 found 1 CPU, using 1 worker thread
12-May-2010 11:24:08.060 using up to 4096 sockets
12-May-2010 11:24:08.119 loading configuration from '/etc/named.conf'
12-May-2010 11:24:08.146 using default UDP/IPv4 port range: [1024, 65535]
12-May-2010 11:24:08.189 using default UDP/IPv6 port range: [1024, 65535]
12-May-2010 11:24:08.196 listening on IPv4 interface lo, 127.0.0.1#53
12-May-2010 11:24:08.198 listening on IPv4 interface eth1, 192.168.1.108#53
12-May-2010 11:24:08.198 listening on IPv4 interface vmnet1, 192.168.157.1#53
12-May-2010 11:24:08.223 listening on IPv4 interface vmnet8, 172.16.237.1#53
12-May-2010 11:24:08.224 listening on IPv4 interface virbr0, 192.168.122.1#53
12-May-2010 11:24:08.224 binding TCP socket: address in use
12-May-2010 11:24:08.273 command channel listening on 127.0.0.1#953
12-May-2010 11:24:08.273 ignoring config file logging statement due to -g option
12-May-2010 11:24:08.277 running

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
本节将详细介绍DNS服务器的rndc配置,实现使用rndc开启DNS的解析日志和刷 新缓存,重载配置文件和关闭DNS服务器,一旦配置好了rndc,这些操作都可以在本地和远程服务器上进行。DNS服务目前算是比较安全的服务,不但进程 的属主改成named用户,而且还运行在一个chroot环境中,将来关闭DNS服务还可能需要使用rndc来控制,这也可能是将来的服务器设计潮流。 rndc是远程DNS服务器进程控制的英文简写,rndc的工作机制使用了/etc/rndc.key和/etc/rndc.conf两个配置文 件,rndc.key文件为锁头,尽管它的名字为key; rndc.conf则是打开rndc.key锁头的对应钥匙;这两个文件可以使用rndc-confgen命令来生成,该命令采用的是对称加密算法;下面 来演示下配置,演示中将使用server来控制client端的DNS服务器,rndc的控制端也可以不是dns服务器…

一:配置client端127.0.0.1上的rndc

[root@client ~]# rndc-confgen |grep -v '^#' //使用rndc-confgen命令生成rndc.key和rndc.conf
key "rndckey" {
algorithm hmac-md5;
secret "q2yvOY2JiyUU2aV4qahzAw==";
};

options {
default-key "rndckey";
default-client 127.0.0.1;
default-port 953;
};

[root@client ~]# rm -rf /etc/rndc.key         //删除默认的rndc.key文件
[root@client ~]# cd /var/named/chroot/etc/
[root@client etc]# cat rndc.key         //将前面rndc-confgen命令生成的“key”一节中的内容写到rndc.key文件中
key "rndckey" {
algorithm hmac-md5;
secret "q2yvOY2JiyUU2aV4qahzAw==";
};

[root@client etc]# chown named.named rndc.key                   //修改文件属主属组主为named
[root@client etc]# ln -s /var/named/chroot/etc/rndc.key /etc/   //符号链接至/etc目录下
[root@client etc]# cat /etc/rndc.conf     //将前面rndc-confgen命令生成的全部内容写到rndc.key文件中
key "rndckey" {
algorithm hmac-md5;
secret "q2yvOY2JiyUU2aV4qahzAw==";
};

options {
default-key "rndckey";
default-client 127.0.0.1;
default-port 953;
};

[root@client etc]# chown named.named /etc/rndc.conf   //修改文件属主属组主为named
[root@client etc]# cat /etc/named.conf 
options {
listen-on port 53 { 192.168.100.20; };
directory       "/var/named";

allow-query     { any; };
allow-transfer {192.168.100.254;};
};

};
include "/etc/named.rfc1912.zones";
include "/etc/rndc.key";    //包含前面定义好的锁头文件

controls {
inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndckey"; }; //允许本机的环回接口使用/etc/rndc.conf文件中rndckey

这把钥匙控制953端口
};
…………………………输出省略…………………………

[root@client etc]# service named restart     //重启服务
Stopping named: [ OK ]
Starting named: [ OK ]
[root@client etc]# netstat -ntpl |grep 953
tcp        0      0 127.0.0.1:953               0.0.0.0:*                   LISTEN      3243/named          
[root@client etc]# service named status 
number of zones: 8
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/1000
tcp clients: 0/100
client is up and running
named (pid 3243) is running...
[root@client etc]# rndc stop            //测试
[root@client etc]# service named status
rndc: connect failed: 127.0.0.1#953: connection refused
named dead but subsys locked

二:配置server端使用rndc控制client

root@client etc]# rndc-confgen |grep -v '^#'   //和前面一样生成新的rndc.key和rndc.conf
key "rndckey" {
algorithm hmac-md5;
secret "p3DukvXgufSpbZdavZy1YA==";
};

options {
default-key "rndckey";
default-client 127.0.0.1;
default-port 953;
};

[root@client etc]# cat /etc/rndc.key //将新生成的文件的“key”节写到/etc/rndc.key文件末尾,并将其改名为rndckey-254
key "rndckey" {
algorithm hmac-md5;
secret "q2yvOY2JiyUU2aV4qahzAw==";
};

key "rndckey-254" {
algorithm hmac-md5;
secret "p3DukvXgufSpbZdavZy1YA==";
};

[root@client etc]# grep 'rndckey-254' /etc/named.conf   //在主配置文件添加下面内容
inet 192.168.100.20 port 953 allow { 192.168.100.254; } keys { "rndckey-254"; };

//允许192.168.100.254这台服务器通过192.168.100.20这个接口,使用rndckey-254这把钥匙来控制953端口

[root@client etc]# service named restart //重启服务
Stopping named: [ OK ]
Starting named: [ OK ]
[root@client etc]# netstat -ntpl |grep 953
tcp        0      0 192.168.100.20:953          0.0.0.0:*                   LISTEN      3869/named          
tcp        0      0 127.0.0.1:953               0.0.0.0:*                   LISTEN      3869/named

[root@server ~]# cat /etc/rndc.conf //将前面生成的文件的全部内容写到server的/etc/rndc.conf文件中,需要修改key的名称和default-server的IP
key "rndckeyi-254" {
algorithm hmac-md5;
secret "p3DukvXgufSpbZdavZy1YA==";
};

options {
default-key "rndckey-254";
default-server 192.168.100.20;
default-port 953;
};
[root@server ~]# chown named.named /etc/rndc.conf   //修改文件属主属组主为named
[root@server ~]# rndc -h       //查看rndc命令帮助
rndc: illegal option -- h
Usage: rndc [-c config] [-s server] [-p port]
[-k key-file ] [-y key] [-V] command

command is one of the following:

reload        Reload configuration file and zones.
reload zone [class [view]]
Reload a single zone.
refresh zone [class [view]]
Schedule immediate maintenance for a zone.
retransfer zone [class [view]]
Retransfer a single zone without checking serial number.
freeze zone [class [view]]
Suspend updates to a dynamic zone.
thaw zone [class [view]]
Enable updates to a frozen dynamic zone and reload it.
reconfig      Reload configuration file and new zones only.
stats         Write server statistics to the statistics file.
querylog      Toggle query logging.
dumpdb [-all|-cache|-zones] [view ...]
Dump cache(s) to the dump file (named_dump.db).
stop          Save pending updates to master files and stop the server.
stop -p       Save pending updates to master files and stop the server
reporting process id.
halt          Stop the server without saving pending updates.
halt -p       Stop the server without saving pending updates reporting
process id.
trace         Increment debugging level by one.
trace level   Change the debugging level.
notrace       Set debugging level to 0.
flush         Flushes all of the server's caches.
flush [view] Flushes the server's cache for a view.
flushname name [view]
Flush the given name from the server's cache(s)
status        Display status of the server.
recursing     Dump the queries that are currently recursing (named.recursing)
*restart      Restart the server.

* == not yet implemented
Version: 9.3.6-P1-RedHat-9.3.6-4.P1.el5

测试:
[root@server ~]# rndc reload    //重载client端DNS配置文件
server reload successful
[root@server ~]# rndc querylog on   //开启解析日志记录功能,开启后默认解析日志保存在client服务器的/var/log/messages文件中,开启此项功能会降低服务器性能
[root@server ~]# dig www.dodo.666.com @192.168.100.20      //测试解析
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> www.dodo.666.com @192.168.100.20
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59157

[root@server ~]# rndc stop //远程关闭client上的DNS服务

[root@client ~]# tail -f /var/log/messages   //客户端上查看日志
Mar 23 23:13:45 client named[3792]: loading configuration from '/etc/named.conf'
Mar 23 23:13:45 client named[3792]: using default UDP/IPv4 port range: [1024, 65535]
Mar 23 23:13:45 client named[3792]: using default UDP/IPv6 port range: [1024, 65535]
Mar 23 23:13:45 client named[3792]: the working directory is not writable
Mar 23 23:14:07 client named[3792]: query logging is now on         //开启解析日志记录功能
Mar 23 23:14:52 client named[3792]: client 192.168.100.254#45815: query: www.dodo.666.com IN A +    //记录的解析日志
Mar 23 23:15:49 client named[3792]: shutting down: flushing changes 
Mar 23 23:15:49 client named[3792]: stopping command channel on 127.0.0.1#953
Mar 23 23:15:49 client named[3792]: stopping command channel on 192.168.100.20#953
Mar 23 23:15:49 client named[3792]: no longer listening on 192.168.100.20#53
Mar 23 23:15:50 client named[3792]: exiting     //成功关闭DNS服务
提示:配置rndc,需要注意服务器时间问题,如果两台服务器的系统时间存在很大出入,那必定rndc命令执行会失败

rndc: connect failed: 127.0.0.1#953: connection refused相关推荐

  1. [bind]rndc: connect failed: 127.0.0.1#953: connection refused

    [root@localhost sbin]# ./named -v bind 9.5.1-p3-v3.0.9 问题现象: [root@localhost sbin]# ./rndc flush -p ...

  2. 解决git下载出现:Failed to connect to 127.0.0.1 port 1080: Connection refused拒绝连接错误

    解决git下载出现:Failed to connect to 127.0.0.1 port 1080: Connection refused拒绝连接错误 文章目录: 一.git拒绝连接原因分析 二.错 ...

  3. 报错curl: (7) Failed to connect to 127.0.0.1 port xxxx: Connection refused

    (pyenv install xxx) 报错curl: (7) Failed to connect to 127.0.0.1 port xxxx: Connection refused的解决方法 问题 ...

  4. git pull 失败:Failed to connect to 127.0.0.1 port 10080: Connection refused

    git pull失败:Failed to connect to 127.0.0.1 port 10080: Connection refused 原因分析:看报错意思是pull时将请求打到了本机的10 ...

  5. 解决出现Failed to connect to 127.0.0.1 port XXXX: Connection refused

    解决出现Failed to connect to 127.0.0.1 port XXXX: Connection refused 一个可能的原因是使用了代理proxy. 解决方法: 查询是否使用代理: ...

  6. Failed to connect to 127.0.0.1 port 1086: Connection refused

    fatal: unable to access 'https://github.com/Homebrew/brew/': Failed to connect to 127.0.0.1 port 108 ...

  7. Git Failed to connect to 127.0.0.1 port 1080: Connection refused 解决

    问题 在git clone时报错:Failed to connect to 127.0.0.1 port 1080: Connection refused 解决方案: 由于设置了动态代理 执行下面命令 ...

  8. MySql - “Can‘t connect to MySQL server on ‘127.0.0.1‘ ([Errno 61] Connection refused)“

    之前用 PyMySql 模组连结本地端的 MySQL 工作的挺顺利的,谁知道在 Mac 重开机后资料库连不上了,报错讯息如下: "Can't connect to MySQL server ...

  9. 可以ping通 但ssh: connect to host 192.168.0.2 port 22: Connection refused

    目录 问题描述 原因 解决 问题描述 自己在树莓派端通过SCP指令给电脑上ubuntu传输文件发现提示:ssh: connect to host 192.168.0.2 port 22: Connec ...

最新文章

  1. Redis安装与调试
  2. OSChina 周一乱弹 —— 嫂子我帮你们照顾放心吧
  3. Redis数据恢复--误删数据后一次吓尿的经历
  4. 多线程环境下,程序真是危机四伏
  5. 新疆计算机二级慨库,2020新疆维吾尔自治区计算机二级易考套餐:二级MS Office高级应用全程班(网课+题库+教材)...
  6. linux java php_Linux PHP 搭建 JavaBridge
  7. python qt designer 重定向_[Python自学] PyQT5-QTDesigner中关联信号和槽
  8. Exchange 跨林迁移 Part3 添加域信任关系
  9. Android Intent机制与常见的用法
  10. 一道很有趣的多元函数求极值问题
  11. 说说命令提示符:tcping命令、tcp协议和ping命令
  12. 使用可靠多播与OPENDDS进行数据分发
  13. 远程访问 Sql Server Express
  14. Linux Wps 缺少字体
  15. Golang 内存分配之逃逸分析
  16. 10-7 spj-查询供应工程 j1 的供应商
  17. 改造家里的开关成为智能开关,保留原有开关控制,零火版,射频遥控器篇(二)
  18. angularjs 常用方法
  19. python pymysql cursors_怎么Pythonpymysql.cursors从mysql存储过程获取INOUT返回结果
  20. 关于vendor-id和product-id的查找

热门文章

  1. 火车车次查询-余票查询--Api接口
  2. 2017.7.4 ACM校内赛 Round 2
  3. Large Margin Partial Label Machine
  4. 销售领域如何开源节流?
  5. checkra1n越狱工具使用及注意事项
  6. 正向代理与反向代理(squid)
  7. Unity+C#开发笔记(一)| 如何动态加载预制件 | ╭(●`∀´●)╯╰(●’◡’●)╮
  8. 工程师什么时机最合适选择跳槽?
  9. JavaScript:将毫秒转换为年/月/日 小时/分钟
  10. 天脉导热冲刺创业板:拟募资4亿 创始人谢毅是初中学历