http://doc.powerdns.com/backends-detail.html
Sample perl backendをRubyに翻訳して動かしてみた。
#!/usr/bin/ruby require "syslog" $stdout.sync = true $syslog = Syslog.open(__FILE__) END { $syslog.close } line = gets line.strip! unless line == "HELO\t1" puts "FAIL" $syslog.err "Recevied '#{line}'" gets exit end puts "OK\tSample backend firing up" while gets $syslog.info "#{$$} Received: #{$_}" $_.strip! arr = $_.split(/\t/) if (arr.length < 6) puts "LOG\tPowerDNS sent unparseable line" puts "FAIL" next end type, qname, qclass, qtype, id, ip = arr if ["A", "ANY"].any? {|i| qtype == i } and qname == "webserver.example.com" $syslog.info "#{$$} Sent A records" puts ["DATA", qname, qclass, "A", 3600, -1, "1.2.3.4"].join("\t") puts ["DATA", qname, qclass, "A", 3600, -1, "1.2.3.5"].join("\t") puts ["DATA", qname, qclass, "A", 3600, -1, "1.2.3.6"].join("\t") elsif ["CNAME", "ANY"].any? {|i| qtype == i } and qname == "www.example.com" $syslog.info "#{$$} Sent CNAME records" puts ["DATA", qname, qclass, "CNAME", 3600, -1, "webserver.example.com"].join("\t") elsif qtype == "MBOXFW" $syslog.info "#{$$} Sent MBOXFW records" puts ["DATA", qname, qclass, "MBOXFW", 3600, -1, "powerdns@example.com"].join("\t") end $syslog.info "#{$$} End of data" puts "END" end
PowerDNSの設定がこんな感じ。
launch=pipe pipe-command=/usr/local/sbin/pdns-backend
問い合わせてみる。
shell> dig @localhost webserver.example.com; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_5.3 <<>> @localhost webserver.example.com
; (1 server found)
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65372
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:
;webserver.example.com. IN A;; ANSWER SECTION:
webserver.example.com. 3600 IN A 1.2.3.4
webserver.example.com. 3600 IN A 1.2.3.5
webserver.example.com. 3600 IN A 1.2.3.6;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Dec 18 06:39:13 2010
;; MSG SIZE rcvd: 87shell> dig @localhost foo.bar.zoo
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_5.3 <<>> @localhost foo.bar.zoo
; (1 server found)
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 39083
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:
;foo.bar.zoo. IN A;; Query time: 11 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Dec 18 06:39:15 2010
;; MSG SIZE rcvd: 29
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2971]: Listening on controlsocket in '/var/run/pdns.controlsocket'
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: Guardian is launching an instance
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: This is a guarded instance of pdns
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: It is advised to bind to explicit addresses with the --local-address option
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: UDP server bound to 0.0.0.0:53
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: TCP server bound to 0.0.0.0:53
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: PowerDNS 2.9.21 (C) 2001-2006 PowerDNS.COM BV (Apr 1 2008, 12:06:01, gcc 4.1.2 20070626 (Red Hat 4.1.2-14)) starting up
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: PowerDNS comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it according to the terms of the GPL version 2.
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: Creating backend connection for TCP
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: Backend launched with banner: OK Sample backend firing up
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: About to create 3 backend threads for UDP
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX pdns[2973]: Backend launched with banner: OK Sample backend firing up
Dec 18 06:35:04 ip-XXX-XXX-XXX-XXX last message repeated 2 times
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q foo.bar.zoo IN ANY -1 127.0.0.1
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q foo.bar.zoo IN SOA -1 127.0.0.1
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q bar.zoo IN SOA -1 127.0.0.1
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q zoo IN SOA -1 127.0.0.1
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q IN SOA -1 127.0.0.1
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX pdns[2973]: Not authoritative for 'foo.bar.zoo', sending servfail to 127.0.0.1 (recursion was desired)
Dec 18 06:35:18 ip-XXX-XXX-XXX-XXX pdns[2973]: Backend launched with banner: OK Sample backend firing up
Dec 18 06:35:28 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2981]: 2981 Received: Q webserver.example.com IN ANY -127.0.0.1
Dec 18 06:35:28 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2981]: 2981 Sent A records
Dec 18 06:35:28 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2981]: 2981 End of data
Dec 18 06:39:08 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2983]: 2983 Received: Q webserver.example.com IN ANY -127.0.0.1
Dec 18 06:39:08 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2983]: 2983 Sent A records
Dec 18 06:39:08 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2983]: 2983 End of data
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q foo.bar.zoo IN ANY -1 127.0.0.1
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q foo.bar.zoo IN SOA -1 127.0.0.1
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q bar.zoo IN SOA -1 127.0.0.1
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q zoo IN SOA -1 127.0.0.1
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 Received: Q IN SOA -1 127.0.0.1
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX /usr/local/sbin/pdns-backend[2979]: 2979 End of data
Dec 18 06:39:15 ip-XXX-XXX-XXX-XXX pdns[2973]: Not authoritative for 'foo.bar.zoo', sending servfail to 127.0.0.1 (recursion was desired)