我正在尝试使用https://www.unbound.net/documentation/pyunbound/examples/example6.html上的示例来修改未绑定DNS服务器上的DNS记录。
在外壳中,我可以执行以下操作:
[user@host-1 ~]$ sudo unbound-control local_data www.example.com A 192.0.2.1
ok
[user@host-1 ~]$ dig www.example.com @127.0.0.1
; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.example.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 128
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.example.com. IN A
;; ANSWER SECTION:
www.example.com. 3600 IN A 192.0.2.1
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Jul 17 12:52:58 PDT 2018
;; MSG SIZE rcvd: 60
[user@host-1 ~]$
我还可以在Python中执行以下操作:
#!/usr/bin/python
from unbound import ub_ctx,ub_strerror,RR_TYPE_A,RR_CLASS_IN
ctx = ub_ctx()
ctx.resolvconf("/etc/resolv.conf")
#add RR to the zone
status = ctx.data_add("another.example.com. IN A 192.0.2.2")
if (status != 0): print "Error data_add:",status, ub_strerror(status)
#lookup for an A record
status, result = ctx.resolve("another.example.com", RR_TYPE_A, RR_CLASS_IN)
if status == 0 and result.havedata:
print "Result:", result.data.as_address_list()
else:
print "No record found"
当我运行它时:
[user@host-1 ~]$ ./unboun_test.py
Result: ['192.0.2.2']
[user@host-1 ~]$
那很好...除了:
[user@host-1 ~]$ dig another.example.com @127.0.0.1
; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> another.example.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 26665
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;another.example.com. IN A
;; AUTHORITY SECTION:
example.com. 10 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2018050827 7200 3600 1209600 3600
;; Query time: 91 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Jul 17 13:04:54 PDT 2018
;; MSG SIZE rcvd: 105
[user@host-1 ~]$
为什么通过python添加的记录对其他进程不可用?我缺少一些“提交”命令吗?我是否完全误解了此模块的目的?
我正在使用CentOS 7,并且已经从epel存储库中安装了yum unbound和unbound-python