Sdílet prostřednictvím


How to duplicate reservations from one server to another?

The problematic scenario is the following:

There are two DHCP servers serving the same set of subnets. For each of the subnets which is being served by both the servers there are two scopes one for each server. The scopes are configured in a way that the active address range in one is in the exclusion range of the other. This way we make sure that a particular IP address is not distributed independently of each other. Now there is a small problem if there are reservations. If the admin has configured the reservations in only one of the scopes then he is on for a surprise. The surprise is that the client for whom you have configured the reservation might get a dynamic IP address from the other DHCP server. This can happen in case the DISCOVER sent by the client reaches the server which does not have reservations first. Thus the essential reason for having a reservation is defeated.

The proper way to handle this scenario is: First configure the scope such that the active address range for both the DHCP servers in question is mutually exclusive. Then write a netsh script for the reservations. This script file (let’s call it reservations.txt) would contain for each reservation an entry like:

dhcp server 10.0.0.1 scope 10.0.0.0 add reservedip 11.0.0.1 <MAC ADDRESS>

Now run this script in the first server 10.0.0.1 by typing:

Netsh exec reservations.txt

After this has been done, you might want to use a word processor to replace the IP address of the server 10.0.0.1 to the IP address of the second DHCP server (say 10.0.0.2).

Once this replacement has been done, you can run the script in the second server. Actually the scripts for both the servers can be run from any place from which there is network connectivity to the DHCP servers. This is because almost most of the operations done through netsh is remotable.

Now for the tough part. If you do have two scopes like what I have mentioned and you did not duplicate the reservations then you have to do the following:

On the DHCP server where you have configured the reservations, you can execute this command for each of the scopes from which you need to export the reservations.

netsh dhcp server <serverIPAddress> scope <scopeAddress> dump>dump.txt

This will dump all the configuration settings for this scope. At the bottom of the dumped text file, you can see the reservations being dumped. Just copy this reservation settings to a new file say “exportedreserv.txt”.

Append to this file exportedreserv.txt the reservation settings from each of the other scopes.

Now on the target machine, do a

netsh exec exportedreserv.txt

You should be done by now. I know it is not completely automatic, but it does save a lot of effort.

If you have any questions please ask me. And also try to leave some comments (I know this is moderated) as I would like to know if this blog has any takers.

Comments

  • Anonymous
    March 29, 2005
    Thanks!
  • Anonymous
    April 14, 2005
    Thank you!
  • Anonymous
    May 09, 2005
    Thanks! This is exactly what I needed to know.

    Now, all you guys have to do is find a way of replicating configuration information using AD and you'll have an enterprise DHCP solution. :P

    Seriously, I know that replicating leases would be impractical and dealing with server specific stuff like who has which scopes which exclusions within those scopes would be tricky to write a GUI for. Still, it's a dream I have. :)

    Still. Getting to use netsh replicate this stuff is far better than doing it by hand. Thanks very much.
  • Anonymous
    August 26, 2005
    Excellent! I've been looking all over for how to do this. We have many reservations and the thought of manually creating them twice was making me ill. ;)
  • Anonymous
    October 20, 2005
    The comment has been removed
  • Anonymous
    November 06, 2005
    Awesome!! Just Awesome! I've been playing around with Netsh for quite awhile and haven't found the right way, but this really works GREAT. My use is for consolidating several domains including their services, and this is COOL. Please post more like this.
    Thankx alot, Palle
  • Anonymous
    January 05, 2006
    The comment has been removed
  • Anonymous
    January 18, 2006
    Thanks a lot! This really cleaned up my operation, and stopped me from having to manually copy all my reservations.
  • Anonymous
    January 19, 2006
    Thanks for this write-up, well written.
  • Anonymous
    January 28, 2006
    Thank you for your write-up. This tool youhave shown is FAR more useful than you showed though.
    I needed to change the subnet mask for 4 of my scopes and retain the existing reservations Using the export: netsh dhcp server <serverIPAddress> scope <scopeAddress> dump>dump.txt
    I then edited the .txt file to replace the subnet mask and then imported the scopes one at a time. This allowed me to move 3 split scope servers to a clustered dhcp server while changing the subnet mask in less than 2 hours. (less than 1 hour if you count all the time I spent looking for a solution - lol).

    Anyway, your blog was a GREAT help and it is unfortunate that the information you have here isn't better publicised.

  • Anonymous
    February 20, 2006
    Awesome! Has anybody written a front end to simply this process for administration yet? It just seems that it may be easier from a lot of users to use a GUI, rather than writting a script every time. This is especially try when you are adding reservations frequently. The closest we've found is Men & Mice, but it falls very short of multiple server administation under a single scope.

    Thanks for the information!
  • Anonymous
    March 02, 2006
    Thanks a lot for having raised this trick to my attention... I was using netsh throught complicated vb scripts previously...
    Is it possible to use it remotely ? I have tried "netsh -r servername options" but it failed. Thanks.
  • Anonymous
    March 25, 2006
    @David, when you want to configure a remote DHCP server all you have to do is put the remote DHCP server name after the "server" keyword.
    Eg: netsh dhcp server \remote-machine add scope ...
    or you can put the IP address also
    netsh dhcp server 10.0.0.1 add scope ...
  • Anonymous
    April 16, 2006
    Hi,
    Is it possible to use this solution to import dhcp reservations from a text file rather than exporting them from another server?

    I would like to create a spreadsheet with client names and corresponding ip reservation, then export this to a text file and import in into dhcp on a windows 2003 server.

    Thanks
  • Anonymous
    May 10, 2006
    The comment has been removed
  • Anonymous
    May 11, 2006
    The comment has been removed
  • Anonymous
    June 19, 2006
    Your article is prety nice. It's a pity that i didn't see it more later.
  • Anonymous
    June 23, 2006
    Thank you man. I am impressed.
  • Anonymous
    July 10, 2006
    I am trying to duplicate the reservations on another DHCP server in a DR site.  The plan is to have clients send requests to both servers, but only have the production DHCP server running to answer these request.  In case of a catastrophic failure, we would manually turn on the DHCP service in the DR site.  Currently both the production site and the DR site are running Windows 2003 Server in a clustered environment.  Both clusters are on seperate subnets.  We are using DoubleTake to replicate the data.

    Brian
  • Anonymous
    September 07, 2006
    <A HREF='http://www.exportersinfo.com'>Exporters</A>
  • Anonymous
    September 13, 2006
    The comment has been removed
  • Anonymous
    September 27, 2006
    <A HREF='http://www.health.ind.in'>Health</A>
  • Anonymous
    November 06, 2006
    i don't understand bout your explaint. can you more spsific again.
  • Anonymous
    November 23, 2006
    Thank you!you saved me about 8 hours of typing with reservations in 3 different scopes on 5 servers
  • Anonymous
    December 28, 2006
    The comment has been removed
  • Anonymous
    January 05, 2007
    Thank you so much! This rocks!
  • Anonymous
    July 18, 2007
    please give me the procedure for duplication dhcp resevations from one server to another
  • Anonymous
    August 29, 2007
    I needed to add the netbios name as a name for the reservation, so adding E-01 to the end of the string you gave added the netbios name of E-01 to the reservation. Thanks for the great tip, saved me hours of work
  • Anonymous
    April 10, 2008
    This is a great article and it is making me think that I have a problem with the way that I am planning to rollout DHCP services. We are collapsing 4 NT 4 DHCP servers into 2 centralized Win2K3 DHCP servers using 50 / 50 scope allocation. I was planning to setup the scopes as you indicated. >For each of the subnets which are being served by both the servers there are two scopes one for each server. The scopes are configured in a way that the active address range in one is in the exclusion range of the other. <<But you bring up this issue of reservations, which I had not thought of. What do you mean by “First configure the scope such that the active address range for both the DHCP servers in question is mutually exclusive.” Can you provide an example?
  • Anonymous
    May 08, 2008
    Thanks!  This got me started doing more resarch on netsh and I found a way to fully automate this process with a batch file and 2 free utilities (grep.exe and sed.exe)  In my environment I was worried about 2 dhcp servers getting out of sync.  So this script will purge all reservations from the 2nd server every night, and import the reservations from the 1st server.  Maybe someone else will find it useful.REM #-- Dump current DHCP configurations --#netsh dhcp server \server1 dump > dhcp_dump.txtnetsh dhcp server \server2 dump > dhcp_purge.txtREM #-- In the purge file, pull out the reservation details and change "add" to "delete" --#grep reservedip dhcp_purge.txt | sed.exe "s/Add/delete/" > dhcp_purge-reservations.txtREM #-- Purge reservations on the second dhcp server --#netsh exec dhcp_purge-reservations.txtREM #-- In the dump file pull out the reservation details and change server IPs. --#grep reservedip dhcp_dump.txt | sed.exe "s/<server1 IP>/<server2 IP>/" > dhcp_new-reservations.txtREM #-- Import the new reservations into the second dhcp server --#netsh exec dhcp_new-reservations.txt
  • Anonymous
    May 13, 2008
    http://blogs.technet.com/teamdhcp/archive/2006/09/19/457383.aspxis an automated VBS that can replicate / copy and sync DHCP reservations
  • Anonymous
    August 09, 2008
    Great article - KISS method (Keep It Simple Stupid)The above mentioned "automated VBS" is noting more then front end for shell commands to netsh. Very heavy and with many errors.This solution is the best one :)
  • Anonymous
    August 16, 2008
    I have been trying to figure out how to do this for years.  "There MUST be a way to do this," I kept muttering to myself as I re-entered all those reservations manually.  Each time I had to do it I regretted not putting more time into figuring this out.  Thank you.  Thank you.  Thank you.
  • Anonymous
    August 27, 2008
    Thanks for the info, AJ... Saved me some time, and more importantly hassle!Tom
  • Anonymous
    November 19, 2008
    What a superb piece of information. So simple yet incredily useful. Thanks man.
  • Anonymous
    December 29, 2008
    Even after almost four years a very useful and much appreciated article. Thanks a lot!
  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/2915934-dhcp-migration
  • Anonymous
    February 17, 2009
    Just wanted to say thanks.I created a dump file from my test DHCP server (running in HyperV)I then just modified the file to include only what I needed, plus new additions, and it worked a treat.A real time saver, THANK YOU
  • Anonymous
    May 07, 2009
    Here's a scenario; I have two servers, the primary server has DHCP running on it and the backup server also has DHCP installed but the sevvice has been stopped.  The second server is configured identically to the primnary server as far as scope configuration but not reservations.  I create a dumplease file from the primary server use rmanage with the -dumplease switch and store it on the backup server for use in case of a failure with the primary server.  Here is how I envision this working:Primary server failsStart DHCP service on backup serverRun rmanage with -makereservation switch pointing to the stored backup file from the primary server.Will this work?Jim
  • Anonymous
    May 11, 2009
    Never mn9ind; tried it and it doesn't work.
  • Anonymous
    May 11, 2009
    I tried it and it worked a treat.Thanks
  • Anonymous
    May 12, 2009
    Mike,You tried it the way I suggested on May 7 and it worked??  I tried it and nothing came into the scope from the dumplease file.  Will you give me some details on EXACTLY what you did?  This would be a wonderful way of always having a DHCP backup ready.  Next to auto-fail-over this is about the best I have seen...if I can get it to work.Jim
  • Anonymous
    July 30, 2009
    The comment has been removed
  • Anonymous
    August 26, 2009
    Steve,What you have outlined is excellent as long as there is no requirement for the client machines to have a specific IP.  Your approach could issue different IP's depending on timing and circumstance.Jim
  • Anonymous
    September 03, 2009
    I ran across this page searching for how to do this and it was great.  Hundreds of reservations moved in short order.  Thank you.
  • Anonymous
    September 17, 2009
    I just used this to bring up a brand new DHCP server on my network. Did the dump command, globally replaced the server name, modified the exclusion ranges and tweaked a couple other things, then saved the file and exec'ed the file.Last time I did this I spend about an hour. This time it took maybe five minutes. Thanks!
  • Anonymous
    September 17, 2009
    I meant to say, last time I did this without knowing about the netsh method, that's why it took an hour. Just in case that wasn't blinkin' obvious.
  • Anonymous
    March 18, 2010
    Used this as basis to rebuild DHCP to extend the subnet mask.  Worked like a dream!  Thanks.
  • Anonymous
    July 08, 2011
    I'm pretty new to this so I'm a little confuse.  Can you light up a little bit?  What do you mean by:This script file (let’s call it reservations.txt) would contain for each reservation an entry like:dhcp server 10.0.0.1 scope 10.0.0.0 add   reservedip 11.0.0.1 <MAC ADDRESS>Now run this script in the first server 10.0.0.1 by typing:How and where did you get it call reservations.txt?  where's the .txt file came from?
  • Anonymous
    July 09, 2012
    Thanks, an old post but still very helpful.