2

On Windows Server 2008 (R2, 32-Bit, I found the following way to set the lease duration for, say, 3600 Seconds (1 Hour).

netsh dhcp server scope 10.0.0.0 set optionvalue 51 DWORD 3600 [→ source]

This is based upon RFC 2132 where optionvalue 51 stands for "IP Address Lease Time". It is possible to set the lease duration to unlimited through the GUI, but I didn't find a way to do this through the command line.


Question: How to set unlimited Lease time through cmd?


In an article applying to Windows Server 2003 (R2, SP1, SP2) I found the following:

… run from the netsh dhcp server mscope> prompt set lease TIME … Specifies the lease duration for clients of the multicast [?!] scope. Specifying -1 sets the duration of the IP address lease to an unlimited or infinite time. [→ source]

Which doesn't help me much.

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
erch
  • 126
  • 10
  • 1
    Use Process Monitor, capture registry writes while you set the Unlimited option in the GUI, then stop the capture and see which registry setting was modified. Whatever you find, do the same with reg.exe on the command line. (Or Powershell.) – Ryan Ries Jun 20 '14 at 19:18
  • 1
    @RyanRies - Sound idea, except DHCP options are stored in an ESE database, not in the registry. – Evan Anderson Jun 20 '14 at 19:46
  • @EvanAnderson I knew I had a good reason for putting that as a comment and not as an answer. :D – Ryan Ries Jun 20 '14 at 21:20

1 Answers1

5

Set the value for option 51 to 4294967295 seconds and it will show up in the GUI as unlimited.

C:\Users\EAnderson>netsh dhcp server scope 10.0.0.0 show optionvalue

Changed the current scope context to 10.0.0.0 scope.

Options for Scope 10.0.0.0:

    DHCP Standard Option :
    General Option Values:
    OptionId : 51
    Option Value:
            Number of Option Elements = 1
            Option Element Type = DWORD
            Option Element Value = 3600 Command completed successfully.

C:\Users\EAnderson>netsh dhcp server scope 10.0.0.0 set option value 51 DWORD 4294967295

Changed the current scope context to 10.10.10.0 scope.

Command completed successfully.

C:\Users\EAnderson>netsh dhcp server scope 10.0.0.0 show optionvalue

Changed the current scope context to 10.0.0.0 scope.

Options for Scope 10.0.0.0:

    DHCP Standard Option :
    General Option Values:
    OptionId : 51
    Option Value:
            Number of Option Elements = 1
            Option Element Type = DWORD
            Option Element Value = -1

Command completed successfully.

Exercise for the reader: Why is 4294967295 special?

Evan Anderson
  • 141,881
  • 20
  • 196
  • 331
  • 2^32 - 1 cute. Not only informative, but entertaining. – Get-HomeByFiveOClock Jun 20 '14 at 20:18
  • Can you set the value at 0 for unlimited? or is max value of 32 bit integer the closest to infinite? – Get-HomeByFiveOClock Jun 20 '14 at 20:30
  • 1
    The command-line tool won't accept 0, and when you set it to "Unlimited" in the GUI the value shown from the command-line tool is "-1". The command-line tool won't let you specify "-1", ergo, set it to (2^32 - 1)... >smile – Evan Anderson Jun 20 '14 at 20:32
  • @Evan Anderson: Works perfectly (after correcting `optionvalue` (n spaces!). My take at the exercise: 2^32 - 1 because the `optionvalue`'s limit is 32 Bits. And the minus one is... because... Besides: Woha - what an answer! – erch Jun 23 '14 at 17:12
  • @erch - I aim to please! http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement – Evan Anderson Jun 23 '14 at 17:21