How to programatically set/view the DNS settings.

How to programmactically set/view the DNS settings that we set in the DNS tab of the Server/Scope/Reservation property page?

Before we investigate how to retrieve this information, let me first explain to you that this information is persisted as a DHCP standard option. The option number that is using is option number 81. Having said that since the DHCP server is using an option number to persist this information, it does not send this information to the client, when the client requests for it. Rather this 81 option is treated as a special option which is used only for persisting the configuration information. The following is how this information is encoded into the option 81.

Option 81 is a DWORD:

1st bit set to '1' if the Check box "Enable DNS Dynamic updates according to settings below" is selected (If this bit is off (as in the case of the screenshot), all other possibilities are ruled out which case the value of the option will always be 0).

2nd bit set to '1' if "Dynamically update DNS A and PTR records for DHCP clients that do not request updates (for example, clients running Windows NT 4.0).

3rd bit set to '1' if Check box "Discard A and PTR records when lease is deleted' is selected

5th bit To choose between 'Dynamically update DNS A and PTR records only if requested by DHCP clients/" (value of 5th bit = '0') And "Always dynamically update DNS A and PTR records" (value of 5th bit = '1')

To double check the encoding, play arround with the various check boxes in the DNS-Scope UI and see the reflected change in the scope option by typing show optionvalue at the scope level.

There are two ways to get the required information programmatically:

1) Using the API DhcpGetOptionValue. This is a public function which can be called. (The option id is 81)

2) We can also use the netsh command to get this information: Eg netsh dhcp server show optionvalue 81

Comments

  • Anonymous
    June 11, 2006
    The comment has been removed