Failovering a DHCP server by Ping from another server


To totally unlock this section you need to Log-in


Login
Let's think a bit about the following scenario: we have a DHCP server, nowadays is usually a virtualized server on a virtual infrastructure like VMware or HyperV, and we want to create a second "sleeping" DHCP server on another server, maybe physical, to use in case the virtual machine on which the DHCP server fails.

NOTE: this solution has been tested on two Windows Server 2008 servers, but it'll work even on Windows Server 2003 or Windows Server 2012 infrastructure.

For this configuration we'll need, first, to replicate/migrate the actual DHCP server configuration from the actual DHCP server on the new server (on which the DHCP has been already installed, but is disabled).

To do this you can read the following article, on HeelpBook: Migrate or duplicate DHCP role in Windows Domain.

Procedure

On the server on which we'll replicate the existing DHCP role could be a domain controller or even a member server, preferably joined in the same domain as the existing DHCP server.

After the backup and restore of the existing DHCP server on the new DHCP server we'll have to:

  • Copy the following code (it's written in VBscript) in a new text file (and then change the file extension from .txt to .exe), changing only the IP address of the existing DHCP server to yours:
  • Dim strTarget, strPingResults
    

    strTarget = "172.17.1.33"

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshExec = WshShell.Exec("ping -n 3 -w 1000 " & strTarget) 'send 3 echo requests, waiting 1 sec each
    strPingResults = LCase(WshExec.StdOut.ReadAll)
    If InStr(strPingResults, "reply from") Then
    Wscript.Quit(0)
    Else
    StartDHCP
    End If

    Private Function StartDHCP()
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='DHCPServer'")
    For each objService in colServiceList
    errReturn = objService.StartService()
    Next
    Wscript.Sleep 20000
    Set colServiceList = objWMIService.ExecQuery("Associators of " _
    & "{Win32_Service.Name='DHCPServer'} Where " _
    & "AssocClass=Win32_DependentService " & "Role=Dependent" )
    For each objService in colServiceList
    objService.StartService()
    Next
    End Function

  • Move the resulting script file on a common and compfortable location (like C:\Scripts).
  • Go on Administrative Tools and then open Task Scheduler.
  • Create a new Basic Task, using an initial Recurring Interval as Daily and specify your script file like in the following screenshot:
  • Failovering a DHCP server by Ping from another server

    Failovering a DHCP server by Ping from another server

  • After this, re-open Task Properties, move on the Triggers tab and then click in the Edit button; change the task properties as in the following screenshot (you can use more narrowed intervals to check DHCP server availability, in the example the interval is 1 hour):
  • Failovering a DHCP server by Ping from another server

    Failovering a DHCP server by Ping from another server

    Now we'll have to configure the account that will run properly the task and this is the SYSTEM account.

  • Go back on the General tab and click on the Change User or Group button.
  • Search for SYSTEM in the Select User or Group windows, and confirm it:
  • Failovering a DHCP server by Ping from another server

    Failovering a DHCP server by Ping from another server

    After this last configuration you can test the scheduled script by changing the IP address in the same script file (with a non-existent IP device/client) and checking if the DHCP Server service is started in the services.msc console:

    Failovering a DHCP server by Ping from another server

    Failovering a DHCP server by Ping from another server

    1 thought on “Failovering a DHCP server by Ping from another server”

    1. Have you ever encountered the scenario in which DHCP is unavailable and you have several (if not all) users correctly connected (but in this case with wrong IP addresses) to LAN but they can’t reach internet, mail services or applications through network? If you want to avoid this scenario you could create a second (or more) DHCP server/s that will be activated if the current DHCP server is down or unreachable.

      Read how on HeelpBook.net!

      Failovering a DHCP server by Ping from another server – http://heelpbook.altervista.org/2014/failovering-a-dhcp-server-by-ping-from-another-server/ #failover #microsoft #dhcp #ping #tutorial #howto

    Comments are closed.