1Net::DNS::Update(3) User Contributed Perl Documentation Net::DNS::Update(3)
2
3
4
6 Net::DNS::Update - DNS dynamic update packet
7
9 use Net::DNS;
10
11 $update = new Net::DNS::Update( 'example.com', 'IN' );
12
13 $update->push( prereq => nxrrset('foo.example.com. A') );
14 $update->push( update => rr_add('foo.example.com. 86400 A 192.168.1.2') );
15
17 Net::DNS::Update is a subclass of Net::DNS::Packet, to be used for
18 making DNS dynamic updates.
19
20 Programmers should refer to RFC2136 for dynamic update semantics.
21
23 new
24 $update = new Net::DNS::Update;
25 $update = new Net::DNS::Update( 'example.com' );
26 $update = new Net::DNS::Update( 'example.com', 'HS' );
27
28 Returns a Net::DNS::Update object suitable for performing a DNS dynamic
29 update. Specifically, it creates a packet with the header opcode
30 set to UPDATE and the zone record type to SOA (per RFC 2136, Section
31 2.3).
32
33 Programs must use the push() method to add RRs to the prerequisite,
34 update, and additional sections before performing the update.
35
36 Arguments are the zone name and the class. The zone and class may be
37 undefined or omitted and default to the default domain from the
38 resolver configuration and IN respectively.
39
40 push
41 $ancount = $update->push( prereq => $rr );
42 $nscount = $update->push( update => $rr );
43 $arcount = $update->push( additional => $rr );
44
45 $nscount = $update->push( update => $rr1, $rr2, $rr3 );
46 $nscount = $update->push( update => @rr );
47
48 Adds RRs to the specified section of the update packet.
49
50 Returns the number of resource records in the specified section.
51
52 Section names may be abbreviated to the first three characters.
53
54 unique_push
55 $ancount = $update->unique_push( prereq => $rr );
56 $nscount = $update->unique_push( update => $rr );
57 $arcount = $update->unique_push( additional => $rr );
58
59 $nscount = $update->unique_push( update => $rr1, $rr2, $rr3 );
60 $nscount = $update->unique_push( update => @rr );
61
62 Adds RRs to the specified section of the update packet provided that
63 the RRs are not already present in the same section.
64
65 Returns the number of resource records in the specified section.
66
67 Section names may be abbreviated to the first three characters.
68
70 The first example below shows a complete program. Subsequent examples
71 show only the creation of the update packet.
72
73 Although the examples are presented using the string form of RRs, the
74 corresponding ( name => value ) form may also be used.
75
76 Add a new host
77 #!/usr/bin/perl
78
79 use Net::DNS;
80
81 # Create the update packet.
82 my $update = new Net::DNS::Update('example.com');
83
84 # Prerequisite is that no A records exist for the name.
85 $update->push( pre => nxrrset('foo.example.com. A') );
86
87 # Add two A records for the name.
88 $update->push( update => rr_add('foo.example.com. 86400 A 192.168.1.2') );
89 $update->push( update => rr_add('foo.example.com. 86400 A 172.16.3.4') );
90
91 # Send the update to the zone's primary master.
92 my $resolver = new Net::DNS::Resolver;
93 $resolver->nameservers('primary-master.example.com');
94
95 my $reply = $resolver->send($update);
96
97 # Did it work?
98 if ($reply) {
99 if ( $reply->header->rcode eq 'NOERROR' ) {
100 print "Update succeeded\n";
101 } else {
102 print 'Update failed: ', $reply->header->rcode, "\n";
103 }
104 } else {
105 print 'Update failed: ', $resolver->errorstring, "\n";
106 }
107
108 Add an MX record for a name that already exists
109 my $update = new Net::DNS::Update('example.com');
110 $update->push( prereq => yxdomain('example.com') );
111 $update->push( update => rr_add('example.com MX 10 mailhost.example.com') );
112
113 Add a TXT record for a name that does not exist
114 my $update = new Net::DNS::Update('example.com');
115 $update->push( prereq => nxdomain('info.example.com') );
116 $update->push( update => rr_add('info.example.com TXT "yabba dabba doo"') );
117
118 Delete all A records for a name
119 my $update = new Net::DNS::Update('example.com');
120 $update->push( prereq => yxrrset('foo.example.com A') );
121 $update->push( update => rr_del('foo.example.com A') );
122
123 Delete all RRs for a name
124 my $update = new Net::DNS::Update('example.com');
125 $update->push( prereq => yxdomain('byebye.example.com') );
126 $update->push( update => rr_del('byebye.example.com') );
127
128 Perform a DNS update signed using a BIND private key file
129 my $update = new Net::DNS::Update('example.com');
130 $update->push( update => rr_add('foo.example.com A 10.1.2.3') );
131 $update->sign_tsig( "$dir/Khmac-sha512.example.com.+165+01018.private" );
132 my $reply = $resolver->send( $update );
133 $reply->verify( $update ) || die $reply->verifyerr;
134
135 Signing the DNS update using a BIND public key file
136 $update->sign_tsig( "$dir/Khmac-sha512.example.com.+165+01018.key" );
137
138 Signing the DNS update using a customised TSIG record
139 $update->sign_tsig( "$dir/Khmac-sha512.example.com.+165+01018.private",
140 fudge => 60
141 );
142
143 Another way to sign a DNS update
144 my $key_name = 'tsig-key';
145 my $key = 'awwLOtRfpGE+rRKF2+DEiw==';
146
147 my $tsig = new Net::DNS::RR("$key_name TSIG $key");
148 $tsig->fudge(60);
149
150 my $update = new Net::DNS::Update('example.com');
151 $update->push( update => rr_add('foo.example.com A 10.1.2.3') );
152 $update->push( additional => $tsig );
153
155 Copyright (c)1997-2000 Michael Fuhr.
156
157 Portions Copyright (c)2002,2003 Chris Reinhardt.
158
159 Portions Copyright (c)2015 Dick Franks.
160
161 All rights reserved.
162
164 Permission to use, copy, modify, and distribute this software and its
165 documentation for any purpose and without fee is hereby granted,
166 provided that the above copyright notice appear in all copies and that
167 both that copyright notice and this permission notice appear in
168 supporting documentation, and that the name of the author not be used
169 in advertising or publicity pertaining to distribution of the software
170 without specific prior written permission.
171
172 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
173 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
174 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
175 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
176 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
177 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
178 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
179
181 perl, Net::DNS, Net::DNS::Packet, Net::DNS::Header, Net::DNS::RR,
182 Net::DNS::Resolver, RFC 2136, RFC 2845
183
184
185
186perl v5.26.3 2018-02-09 Net::DNS::Update(3)