Microsoft Windows DHCP Team Blog

The world's most deployed DHCP Server! Deploy and discuss about your fav. server, here!

Blogs

How to programatically set/view the DNS settings.

  • Comments 5
  • Likes
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
  • I can go into the DHCP Admin GUI and change the values on the DNS tab of a reserved lease and see it reflected in netsh with

    show reservedoptionvalue <reservedIP>

    and see the setting of Option 81 (decimal), but I am unable to programatically SET the value using the expected syntax of

    set reservedoptionvalue <reservedID> 81 DWORD 0

    receiving the error "The specified option does not exist".  It would appear that the value is read-only as far as netsh is concerned.  Does anyone know of a solution?

  • When I try to change this option value at the scope level via NetSH I get this error: The specified option does not exist.

    I can see the value using show optionvalue even though it doesn't "exist".

    On my test server I tried adding the optiondefinition: NETSH Dhcp Server x.x.x.x Add Optiondef 81 "DNS Settings" DWORD 0 comment="Settings for DNS tab" 0

    Once I did that I was able to set the option value via NetSH, and it changes the DNS settings tab as expected.  Great!

    My only questions are:  Are there any unforeseen ill effects to adding the option definition?  Why is the option value not available by default?

    Although it works, I'm afraid to modify my production servers in this manner.  I'd really like to be able to script these settings though.

  • Hey,

    You can set or retrieve the DNS settings using the command

    netsh dhcp server set dnsconfig

    netsh dhcp server show dnsconfig

    Thanks

    Raunak Pandya

    DHCP Server Team

  • "at the scope level"

    It works for me as a server-wide setting, but not for specific reservations, which is what I need.  I've scripted the rest of the reservation creation process, but I still have to go into the GUI to uncheck the Dynamic Updates box.

    I may look into adding option 81 as AJW suggested, but it would be nice to have a little more info.

  • The following netsh command would enable name protection for a scope in Dhcp Server :

    netsh dhcp server v4 scope <scope_IpAddress> set nameprotection enable=1

    The same command is available at global level (i.e. ipv4 context)

    -Ravi

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment