1Net::DNS::Update(3) User Contributed Perl Documentation Net::DNS::Update(3)
2
3
4
6 Net::DNS::Update - Create a DNS update packet
7
9 "use Net::DNS::Update;"
10
12 "Net::DNS::Update" is a subclass of "Net::DNS::Packet", to be used for
13 making DNS dynamic updates. Programmers should refer to RFC 2136 for
14 the semantics of dynamic updates.
15
16 WARNING: This code is still under development. Please use with cau‐
17 tion on production nameservers.
18
20 new
21
22 $packet = Net::DNS::Update->new;
23 $packet = Net::DNS::Update->new('example.com');
24 $packet = Net::DNS::Update->new('example.com', 'HS');
25
26 Returns a "Net::DNS::Update" object suitable for performing a DNS
27 dynamic update. Specifically, it creates a packet with the header
28 opcode set to UPDATE and the zone record type to SOA (per RFC 2136,
29 Section 2.3).
30
31 Programs must use the "push" method to add RRs to the prerequisite,
32 update, and additional sections before performing the update.
33
34 Arguments are the zone name and the class. If the zone is omitted, the
35 default domain will be taken from the resolver configuration. If the
36 class is omitted, it defaults to IN.
37
38 Future versions of "Net::DNS" may provide a simpler interface for mak‐
39 ing dynamic updates.
40
42 The first example below shows a complete program; subsequent examples
43 show only the creation of the update packet.
44
45 Add a new host
46
47 #!/usr/bin/perl -w
48
49 use Net::DNS;
50 use strict;
51
52 # Create the update packet.
53 my $update = Net::DNS::Update->new('example.com');
54
55 # Prerequisite is that no A records exist for the name.
56 $update->push(pre => nxrrset('foo.example.com. A'));
57
58 # Add two A records for the name.
59 $update->push(update => rr_add('foo.example.com. 86400 A 192.168.1.2'));
60 $update->push(update => rr_add('foo.example.com. 86400 A 172.16.3.4'));
61
62 # Send the update to the zone's primary master.
63 my $res = Net::DNS::Resolver->new;
64 $res->nameservers('primary-master.example.com');
65
66 my $reply = $res->send($update);
67
68 # Did it work?
69 if ($reply) {
70 if ($reply->header->rcode eq 'NOERROR') {
71 print "Update succeeded\n";
72 } else {
73 print 'Update failed: ', $reply->header->rcode, "\n";
74 }
75 } else {
76 print 'Update failed: ', $res->errorstring, "\n";
77 }
78
79 Add an MX record for a name that already exists
80
81 my $update = Net::DNS::Update->new('example.com');
82 $update->push(pre => yxdomain('example.com'));
83 $update->push(update => rr_add('example.com MX 10 mailhost.example.com'));
84
85 Add a TXT record for a name that doesn't exist
86
87 my $update = Net::DNS::Update->new('example.com');
88 $update->push(pre => nxdomain('info.example.com'));
89 $update->push(update => rr_add('info.example.com TXT "yabba dabba doo"'));
90
91 Delete all A records for a name
92
93 my $update = Net::DNS::Update->new('example.com');
94 $update->push(pre => yxrrset('foo.example.com A'));
95 $update->push(update => rr_del('foo.example.com A'));
96
97 Delete all RRs for a name
98
99 my $update = Net::DNS::Update->new('example.com');
100 $update->push(pre => yxdomain('byebye.example.com'));
101 $update->push(update => rr_del('byebye.example.com'));
102
103 Perform a signed update
104
105 my $key_name = 'tsig-key';
106 my $key = 'awwLOtRfpGE+rRKF2+DEiw==';
107
108 my $update = Net::DNS::Update->new('example.com');
109 $update->push(update => rr_add('foo.example.com A 10.1.2.3'));
110 $update->push(update => rr_add('bar.example.com A 10.4.5.6'));
111 $update->sign_tsig($key_name, $key);
112
113 Another way to perform a signed update
114
115 my $key_name = 'tsig-key';
116 my $key = 'awwLOtRfpGE+rRKF2+DEiw==';
117
118 my $update = Net::DNS::Update->new('example.com');
119 $update->push(update => rr_add('foo.example.com A 10.1.2.3'));
120 $update->push(update => rr_add('bar.example.com A 10.4.5.6'));
121 $update->push(additional => Net::DNS::RR->new("$key_name TSIG $key"));
122
123 Perform a signed update with a customized TSIG record
124
125 my $key_name = 'tsig-key';
126 my $key = 'awwLOtRfpGE+rRKF2+DEiw==';
127
128 my $tsig = Net::DNS::RR->new("$key_name TSIG $key");
129 $tsig->fudge(60);
130
131 my $update = Net::DNS::Update->new('example.com');
132 $update->push(update => rr_add('foo.example.com A 10.1.2.3'));
133 $update->push(update => rr_add('bar.example.com A 10.4.5.6'));
134 $update->push(additional => $tsig);
135
137 This code is still under development. Please use with caution on pro‐
138 duction nameservers.
139
141 Copyright (c) 1997-2002 Michael Fuhr.
142
143 Portions Copyright (c) 2002-2004 Chris Reinhardt.
144
145 All rights reserved. This program is free software; you may redis‐
146 tribute it and/or modify it under the same terms as Perl itself.
147
149 perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Header,
150 Net::DNS::Packet, Net::DNS::Question, Net::DNS::RR, RFC 2136, RFC 2845
151
152
153
154perl v5.8.8 2007-08-01 Net::DNS::Update(3)