22 pers. connectées au site
Manuel Pear
Examples -- DNS Updates
Examples --
DNS Updates -- RFC 2136 DNS Updates
RFC 2136 DNS Updates
By constructing a specially formatted DNS packet and sending it to a nameserver, a dynamic DNS update can be performed very easily. RFC 2136 defines some variations of a DNS packet that are used by Net_DNS to request an update. The nameserver must first be configured to accept DNS updates, a key must be established between the client and server, and most importantly, the PHP mhash extension must be included for processing the MD5 digest of the key.
The format of the DNS packet is very specific and requires in-depth knowledge of how DNS updates work. Net_DNS currently does not support any abstraction of these specially formatted packets. Packets must currently be crafted and sent manually. The full formatting of update packets can be found in RFC 2136.
For a complete listing of all of the fields that are available for DNS updates, please review RFC2136 (http://www.ietf.org/rfc/rfc2136.txt). The following examples show the simplest forms of a DNS update.
Exemple 54-1. Sending a dynamic DNS update packet to a nameserver
- <?php
- require_once 'Net/DNS.php';
-
- $resolver = new Net_DNS_Resolver();
-
- $resolver->nameservers = array('192.168.0.254');
-
- $packet = new Net_DNS_Packet();
-
- $packet->header = new Net_DNS_Header();
- $packet->header->id = $resolver->nextid();
- $packet->header->qr = 0;
- $packet->header->opcode = "UPDATE";
-
- $packet->question[0] = new Net_DNS_Question('example.com', "SOA", "IN");
-
- $packet->answer = array();
-
- $rrDelete =& Net_DNS_RR::factory("example.com. 0 IN A 192.0.34.166");
- $rrAdd =& Net_DNS_RR::factory("example.com. 3600 IN A 192.0.34.166");
- $packet->authority[0] = $rrDelete;
- $packet->authority[1] = $rrAdd;
- $tsig =& Net_DNS_RR::factory("keyname.as.specified.in.server. TSIG ThisIsMyKey");
- $packet->additional = array($tsig);
- $packet->header->qdcount = count($packet->question);
- $packet->header->ancount = count($packet->answer);
- $packet->header->nscount = count($packet->authority);
- $packet->header->arcount = count($packet->additional);
- $response = $resolver->send_tcp($packet, $packet->data());
- if ($response->header->rcode != "NOERROR") {
- return($response->header->rcode);
- }
-
-
- ?>
|
Remonter