Justin Cooksey

Well it was bound to happen! Three years now after being asked to migrate DHCP from Windows DHCP server to Cisco Routers, and automating that convertion, it's finally going back the other way.

This time the PowerShell script will read through the file (an exported Cisco Router configuration) and build the Scopes in the Windows DHCP Role. The script will need to be run on the server becoming the DHCP server for those new scopes. The user would need to have administrator privilege to allow the DHCP settings to be made.

The script follows these steps:

  1. Reads through the configuration file and, using Regular Expressions, finds all DHCP Pools (Scopes), Static Assignments and Exclusions.
  2. Creates all the Scopes, along with all options found under that Pool in the router configuration file.
  3. Processes the Exclusions in to each Scope
  4. Process all static assignments

Still a little bit in the works at the time of this posting, but testing across multiple configurations has found it working well. The Code Repository can be found on GitHub

Some DHCP Options are being handled as follows.

Code Cisco Config Option Description
3 default-router Default Gateway
6 dns-server Domain Nameservers
15 domain-name Domain Name
42 option 42 ip NTP Servers
43 option 43 hex Vendor Specific Option, usually WAP Controller IP
51 lease Lease time
66 next-server TFTP Server
66 option 66 ip TFTP Server
67 bootfile Boot filename
67 option 67 ascii Boot filename

Example Cisco Config

ip dhcp excluded-address 10.10.0.1 10.10.1.0
ip dhcp excluded-address 10.10.3.220 10.10.3.223
ip dhcp excluded-address 192.168.0.1 192.168.0.9
!
ip dhcp pool PoolNumber1
 network 10.10.0.0 255.255.248.0
 update dns both override
 dns-server 10.10.255.1 10.10.255.2 
 domain-name domainname.local
 option 42 ip 10.10.249.11 10.10.248.11 
 default-router 10.10.0.1 
 lease 8
!
ip dhcp pool PoolNumber2
 network 192.168.0.0 255.255.255.0
 dns-server 192.168.0.10
 option 43 hex f108.0afe.0064
 default-router 192.168.0.1
!
ip dhcp pool Device1
 host 10.10.1.30 255.255.248.0
 client-identifier 01b7.37eb.1f1a.0a
 default-router 10.10.0.1 
!
ip dhcp pool Device2
 host 192.168.0.44 255.255.255.0
 client-identifier 0132.c19f.b7f3.3b

This script makes use of the IPv4Calc Module

Share this on: Twitter Facebook LinkedIn Reddit