{
    "mode": "perldoc",
    "parameter": "Net::DNS::Update",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ADNS%3A%3AUpdate/json",
    "generated": "2026-06-15T16:46:52Z",
    "synopsis": "use Net::DNS;\n$update = Net::DNS::Update->new( 'example.com', 'IN' );\n$update->push( prereq => nxrrset('host.example.com. AAAA') );\n$update->push( update => rradd('host.example.com. 86400 AAAA 2001::DB8::F00') );",
    "sections": {
        "NAME": {
            "content": "Net::DNS::Update - DNS dynamic update packet\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Net::DNS;\n\n$update = Net::DNS::Update->new( 'example.com', 'IN' );\n\n$update->push( prereq => nxrrset('host.example.com. AAAA') );\n$update->push( update => rradd('host.example.com. 86400 AAAA 2001::DB8::F00') );\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Net::DNS::Update is a subclass of Net::DNS::Packet, to be used for making DNS dynamic updates.\n\nProgrammers should refer to RFC2136 for dynamic update semantics.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new\n$update = Net::DNS::Update->new;\n$update = Net::DNS::Update->new( 'example.com' );\n$update = Net::DNS::Update->new( 'example.com', 'IN' );\n\nReturns a Net::DNS::Update object suitable for performing a DNS dynamic update. Specifically, it\ncreates a packet with the header opcode set to UPDATE and the zone record type to SOA (per RFC\n2136, Section 2.3).\n\nPrograms must use the push() method to add RRs to the prerequisite and update sections before\nperforming the update.\n\nArguments are the zone name and the class. The zone and class may be undefined or omitted and\ndefault to the default domain from the resolver configuration and IN respectively.\n\npush\n$ancount = $update->push( prereq => $rr );\n$nscount = $update->push( update => $rr );\n$arcount = $update->push( additional => $rr );\n\n$nscount = $update->push( update => $rr1, $rr2, $rr3 );\n$nscount = $update->push( update => @rr );\n\nAdds RRs to the specified section of the update packet.\n\nReturns the number of resource records in the specified section.\n\nSection names may be abbreviated to the first three characters.\n\nuniquepush\n$ancount = $update->uniquepush( prereq => $rr );\n$nscount = $update->uniquepush( update => $rr );\n$arcount = $update->uniquepush( additional => $rr );\n\n$nscount = $update->uniquepush( update => $rr1, $rr2, $rr3 );\n$nscount = $update->uniquepush( update => @rr );\n\nAdds RRs to the specified section of the update packet provided that the RRs are not already\npresent in the same section.\n\nReturns the number of resource records in the specified section.\n\nSection names may be abbreviated to the first three characters.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "The first example below shows a complete program. Subsequent examples show only the creation of\nthe update packet.\n\nAlthough the examples are presented using the string form of RRs, the corresponding ( name =>\nvalue ) form may also be used.\n",
            "subsections": [
                {
                    "name": "Add a new host",
                    "content": "#!/usr/bin/perl\n\nuse Net::DNS;\n\n# Create the update packet.\nmy $update = Net::DNS::Update->new('example.com');\n\n# Prerequisite is that no address records exist for the name.\n$update->push( pre => nxrrset('host.example.com. A') );\n$update->push( pre => nxrrset('host.example.com. AAAA') );\n\n# Add two address records for the name.\n$update->push( update => rradd('host.example.com. 86400 A 192.0.2.1') );\n$update->push( update => rradd('host.example.com. 86400 AAAA 2001:DB8::1') );\n\n# Send the update to the zone's primary nameserver.\nmy $resolver = Net::DNS::Resolver->new();\n$resolver->nameservers('DNSprimary.example.com');\n\nmy $reply = $resolver->send($update);\n\n# Did it work?\nif ($reply) {\nif ( $reply->header->rcode eq 'NOERROR' ) {\nprint \"Update succeeded\\n\";\n} else {\nprint 'Update failed: ', $reply->header->rcode, \"\\n\";\n}\n} else {\nprint 'Update failed: ', $resolver->errorstring, \"\\n\";\n}\n"
                },
                {
                    "name": "Add an MX record for a name that already exists",
                    "content": "my $update = Net::DNS::Update->new('example.com');\n$update->push( prereq => yxdomain('example.com') );\n$update->push( update => rradd('example.com MX 10 mailhost.example.com') );\n"
                },
                {
                    "name": "Add a TXT record for a name that does not exist",
                    "content": "my $update = Net::DNS::Update->new('example.com');\n$update->push( prereq => nxdomain('info.example.com') );\n$update->push( update => rradd('info.example.com TXT \"yabba dabba doo\"') );\n"
                },
                {
                    "name": "Delete all A records for a name",
                    "content": "my $update = Net::DNS::Update->new('example.com');\n$update->push( prereq => yxrrset('host.example.com A') );\n$update->push( update => rrdel('host.example.com A') );\n"
                },
                {
                    "name": "Delete all RRs for a name",
                    "content": "my $update = Net::DNS::Update->new('example.com');\n$update->push( prereq => yxdomain('byebye.example.com') );\n$update->push( update => rrdel('byebye.example.com') );\n"
                },
                {
                    "name": "Perform DNS update signed using a key generated by BIND tsig-keygen",
                    "content": "my $update = Net::DNS::Update->new('example.com');\n$update->push( update => rradd('host.example.com AAAA 2001:DB8::1') );\n$update->signtsig( $keyfile );\nmy $reply = $resolver->send( $update );\n$reply->verify( $update ) || die $reply->verifyerr;\n"
                },
                {
                    "name": "Signing the DNS update using a customised TSIG record",
                    "content": "$update->signtsig( $keyfile, fudge => 60 );\n"
                },
                {
                    "name": "Signing the DNS update using private key generated by BIND dnssec-keygen",
                    "content": "$update->signtsig( \"$dir/Khmac-sha512.example.com.+165+01018.private\" );\n"
                },
                {
                    "name": "Signing the DNS update using public key generated by BIND dnssec-keygen",
                    "content": "$update->signtsig( \"$dir/Khmac-sha512.example.com.+165+01018.key\" );\n"
                },
                {
                    "name": "Another way to sign a DNS update",
                    "content": "use Net::DNS::RR::TSIG;\n\nmy $tsig = create Net::DNS::RR::TSIG( $keyfile );\n$tsig->fudge(60);\n\nmy $update = Net::DNS::Update->new('example.com');\n$update->push( update     => rradd('host.example.com AAAA 2001:DB8::1') );\n$update->push( additional => $tsig );\n"
                }
            ]
        },
        "COPYRIGHT": {
            "content": "Copyright (c)1997-2000 Michael Fuhr.\n\nPortions Copyright (c)2002,2003 Chris Reinhardt.\n\nPortions Copyright (c)2015 Dick Franks.\n\nAll rights reserved.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Permission to use, copy, modify, and distribute this software and its documentation for any\npurpose and without fee is hereby granted, provided that the original copyright notices appear\nin all copies and that both copyright notice and this permission notice appear in supporting\ndocumentation, and that the name of the author not be used in advertising or publicity\npertaining to distribution of the software without specific prior written permission.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING\nBUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "perl, Net::DNS, Net::DNS::Packet, Net::DNS::Header, Net::DNS::RR, Net::DNS::Resolver, RFC 2136,\nRFC 2845\n",
            "subsections": []
        }
    },
    "summary": "Net::DNS::Update - DNS dynamic update packet",
    "flags": [],
    "examples": [
        "The first example below shows a complete program. Subsequent examples show only the creation of",
        "the update packet.",
        "Although the examples are presented using the string form of RRs, the corresponding ( name =>",
        "value ) form may also be used.",
        "#!/usr/bin/perl",
        "use Net::DNS;",
        "# Create the update packet.",
        "my $update = Net::DNS::Update->new('example.com');",
        "# Prerequisite is that no address records exist for the name.",
        "$update->push( pre => nxrrset('host.example.com. A') );",
        "$update->push( pre => nxrrset('host.example.com. AAAA') );",
        "# Add two address records for the name.",
        "$update->push( update => rradd('host.example.com. 86400 A 192.0.2.1') );",
        "$update->push( update => rradd('host.example.com. 86400 AAAA 2001:DB8::1') );",
        "# Send the update to the zone's primary nameserver.",
        "my $resolver = Net::DNS::Resolver->new();",
        "$resolver->nameservers('DNSprimary.example.com');",
        "my $reply = $resolver->send($update);",
        "# Did it work?",
        "if ($reply) {",
        "if ( $reply->header->rcode eq 'NOERROR' ) {",
        "print \"Update succeeded\\n\";",
        "} else {",
        "print 'Update failed: ', $reply->header->rcode, \"\\n\";",
        "} else {",
        "print 'Update failed: ', $resolver->errorstring, \"\\n\";",
        "my $update = Net::DNS::Update->new('example.com');",
        "$update->push( prereq => yxdomain('example.com') );",
        "$update->push( update => rradd('example.com MX 10 mailhost.example.com') );",
        "my $update = Net::DNS::Update->new('example.com');",
        "$update->push( prereq => nxdomain('info.example.com') );",
        "$update->push( update => rradd('info.example.com TXT \"yabba dabba doo\"') );",
        "my $update = Net::DNS::Update->new('example.com');",
        "$update->push( prereq => yxrrset('host.example.com A') );",
        "$update->push( update => rrdel('host.example.com A') );",
        "my $update = Net::DNS::Update->new('example.com');",
        "$update->push( prereq => yxdomain('byebye.example.com') );",
        "$update->push( update => rrdel('byebye.example.com') );",
        "my $update = Net::DNS::Update->new('example.com');",
        "$update->push( update => rradd('host.example.com AAAA 2001:DB8::1') );",
        "$update->signtsig( $keyfile );",
        "my $reply = $resolver->send( $update );",
        "$reply->verify( $update ) || die $reply->verifyerr;",
        "$update->signtsig( $keyfile, fudge => 60 );",
        "$update->signtsig( \"$dir/Khmac-sha512.example.com.+165+01018.private\" );",
        "$update->signtsig( \"$dir/Khmac-sha512.example.com.+165+01018.key\" );",
        "use Net::DNS::RR::TSIG;",
        "my $tsig = create Net::DNS::RR::TSIG( $keyfile );",
        "$tsig->fudge(60);",
        "my $update = Net::DNS::Update->new('example.com');",
        "$update->push( update     => rradd('host.example.com AAAA 2001:DB8::1') );",
        "$update->push( additional => $tsig );"
    ],
    "see_also": []
}