class Dnsruby::Update

The first example below shows a complete program; subsequent examples show only the creation of the update packet.

Add a new host

require 'Dnsruby'

# Create the update packet.
update = Dnsruby::Update.new('example.com')

# Prerequisite is that no A records exist for the name.
update.absent('foo.example.com.', 'A')

# Add two A records for the name.
update.add('foo.example.com.', 'A', 86400, '192.168.1.2')
update.add('foo.example.com.', 'A', 86400, '172.16.3.4')

# Send the update to the zone's primary master.
res = Dnsruby::Resolver.new({:nameserver => 'primary-master.example.com'})

begin
    reply = res.send_message(update)
    print "Update succeeded\n"
 rescue Exception => e
    print 'Update failed: #{e}\n'
 end

Add an MX record for a name that already exists

update = Dnsruby::Update.new('example.com')
update.present('example.com')
update.add('example.com', Dnsruby::Types.MX, 86400, 10, 'mailhost.example.com')

Add a TXT record for a name that doesn’t exist

update = Dnsruby::Update.new('example.com')
update.absent('info.example.com')
update.add('info.example.com', Types.TXT, 86400, "yabba dabba doo"')

Delete all A records for a name

update = Dnsruby::Update.new('example.com')
update.present('foo.example.com', 'A')
update.delete('foo.example.com', 'A')

Delete all RRs for a name

update = Dnsruby::Update.new('example.com')
update.present('byebye.example.com')
update.delete('byebye.example.com')

Perform a signed update

key_name = 'tsig-key'
key      = 'awwLOtRfpGE+rRKF2+DEiw=='

update = Dnsruby::Update.new('example.com')
update.add('foo.example.com', 'A', 86400, '10.1.2.3'))
update.add('bar.example.com', 'A', 86400, '10.4.5.6'))
res.tsig=(key_name,key)