Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

DHCP

10K

Solutions

14K

Contributors

The Dynamic Host Configuration Protocol (DHCP) is an auto configuration protocol used on IP networks and an extension of the Bootstrap Protocol. DHCP allows for computers to be configured automatically to communicate with each other over an IP network without the need for manual setup by a network administrator. The implementation of DHCP relies on a DHCP server to hand out network configuration information to DHCP-capable clients that request an IP address (and other information required or useful in communicating with other devices on an IP network). In addition to an IP address, common configuration information served over DHCP includes a default gateway, subnet mask and DNS sever(s).

Share tech news, updates, or what's on your mind.

Sign up to Post

Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
0
 

Expert Comment

by:Derek Bannard
Comment Utility
Well... couldn't figure out how to set the inner "Option" on the policy, but everything else is here.

Remember to run this in an administrative powershell prompt on the DHCP server.
You need to restart the DHCPServer service after running this and set the PXEClient settings in the 3 policies.  The BIOS policy is blank, the UEFI polcies are the default of "PXEClient".

The command to run is "Set-DHCPPXEOptions"

Enjoy!


<# 
.Synopsis
	Receives user input, gets the list of DHCP options, classes and policies, then sets them if they don't exist.
.DESCRIPTION 
	Enter the option number, class name or policy name where approporiate.
.NOTES 
	Author: Derek Bannard
.EXAMPLE
	Import-Module .\DHCPPXEOptions.psm1
	Loads the modules to perform the DHCP functions.
.EXAMPLE
	Get-DHCPOptions
	Lists missing options for use with Set-DHCPPXEOptions function.
.EXAMPLE
	Get-DHCPClasses
	Lists missing classes for use with Set-DHCPPXEOptions function.
.EXAMPLE
	Get-DHCPPolicies
	Lists missing policies for use with Set-DHCPPXEOptions function.
.EXAMPLE
	Set-DHCPPXEOptions
	Creates all missing options, classes and policies for BIOS/UEFI PXE co-existance.
#>

<#
=================================================
Error Preferences
=================================================
#>
$errpref = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"


<#
=================================================
Script Variables, comma separated
=================================================
#>
[string[]]$DHCPOptions = 060,066,067
[string[]]$DHCPClasses = "PXEClient:Arch:00000","PXEClient:Arch:00006","PXEClient:Arch:00007"
[string[]]$DHCPPolicies = "PXEClient (BIOS x86 & x64)","UEFI 32-Bit DHCP Policy","UEFI 64-Bit DHCP Policy"

[string[]]$rtnDHCPOptions = @()
[string[]]$rtnDHCPClasses = @()
[string[]]$rtnDHCPPolicies = @()


<#
=================================================
Script Get Functions
=================================================
#>
Function Get-DHCPOptions{
	$arrayOptions = New-Object System.Collections.ArrayList

	ForEach ($DHCPOption in $DHCPOptions){
		Try{
			If((Get-DhcpServerv4OptionDefinition -OptionId $DHCPOption) -eq $null){
				Write-Verbose "OptionId $DHCPOption is not present."
				$arrayOptions.Add($DHCPOption) | Out-Null
				}
			Else{
				Write-Verbose "OptionId $DHCPOption is already present."
				}
		}
		Catch{
		}
	}
	$global:rtnDHCPOptions = $arrayOptions
}


Function Get-DHCPClasses{
	$arrayClasses = New-Object System.Collections.ArrayList

	ForEach ($DHCPClass in $DHCPClasses){
		Try{
			If((Get-DhcpServerv4Class -Type Vendor | Where {$_.AsciiData -eq $DHCPClass}) -eq $null){
				Write-Verbose "OptionId $DHCPClass is not present."
				$arrayClasses.Add($DHCPClass) | Out-Null
				}
			Else{
				Write-Verbose "OptionId $DHCPClass is already present."
				}
		}
		Catch{
		}
	}
	$global:rtnDHCPClasses = $arrayClasses
}


Function Get-DHCPPolicies{
	$arrayPolicies = New-Object System.Collections.ArrayList

	ForEach ($DHCPPolicy in $DHCPPolicies){
		Try{
			If((Get-DhcpServerv4Policy -Name $DHCPPolicy) -eq $null){
				Write-Verbose "OptionId $DHCPPolicy is not present."
				$arrayPolicies.Add($DHCPPolicy) | Out-Null
				}
			Else{
				Write-Verbose "OptionId $DHCPPolicy is already present."
				}
		}
		Catch{
		}
	}
	$global:rtnDHCPPolicies = $arrayPolicies
}


<#
=================================================
Script Set Function
=================================================
#>
Function Set-DHCPPXEOptions{
	If($rtnDHCPOptions){
		ForEach ($rtnDHCPOption in $rtnDHCPOptions){
			If($rtnDHCPOption -eq "060"){
				Try{
					Write-Output "Adding OptionId 060..."
					Add-DhcpServerv4OptionDefinition -Name "PXEClient" -Description "PXE Support" -DefaultValue "PXEClient" -OptionId 060 -Type String
				}
				Catch{
				}
			}
			ElseIf($rtnDHCPOption -eq "066"){
				Try{
					Write-Output "Adding OptionId 066..."
					Add-DhcpServerv4OptionDefinition -Name "Boot Server Host Name" -Description "TFTP boot server host name" -OptionId 066 -Type String
				}
				Catch{
				}
			}
			ElseIf($rtnDHCPOption -eq "067"){
				Try{
					Write-Output "Adding OptionId 067..."
					Add-DhcpServerv4OptionDefinition -Name "Bootfile Name" -Description "Bootfile Name" -OptionId 067 -Type String
				}
				Catch{
				}
			}
			Else{
				Write-Output "Undefined options cannot be added!"
			}
		}
	}
	Else{
		Write-Output "No Options are required to be added."
	}


	If($rtnDHCPClasses){
		ForEach ($rtnDHCPClass in $rtnDHCPClasses){
			If($rtnDHCPClass -eq "PXEClient:Arch:00000"){
				Try{
					Write-Output "Adding PXEClient (BIOS x86 & x64) Class..."
					Add-DhcpServerv4Class -Name "PXEClient (BIOS x86 & x64)" -Type Vendor -Data "0x505845436c69656e743a417263683a3030303030" -Description "PXEClient:Arch:00000"
				}
				Catch{
				}
			}
			ElseIf($rtnDHCPClass -eq "PXEClient:Arch:00006"){
				Try{
					Write-Output "Adding UEFI 32-Bit DHCP Class..."
					Add-DhcpServerv4Class -Name "PXEClient (UEFI x86)" -Type Vendor -Data "0x505845436c69656e743a417263683a3030303036" -Description "PXEClient:Arch:00006"
				}
				Catch{
				}
			}
			ElseIf($rtnDHCPClass -eq "PXEClient:Arch:00007"){
				Try{
					Write-Output "Adding UEFI 64-Bit DHCP Class..."
					Add-DhcpServerv4Class -Name "PXEClient (UEFI x64)" -Type Vendor -Data "0x505845436c69656e743a417263683a3030303037" -Description "PXEClient:Arch:00007"
				}
				Catch{
				}
			}
			Else{
				Write-Output "Undefined classes cannot be added!"
			}
		}
	}
	Else{
		Write-Output "No Classes are required to be added."
	}


	If($rtnDHCPPolicies){
		ForEach ($rtnDHCPPolicy in $rtnDHCPPolicies){
			If($rtnDHCPPolicy -eq "PXEClient (BIOS x86 & x64)"){
				Try{
					Write-Output "Adding PXEClient (BIOS x86 & x64) Policy..."
					Add-DhcpServerv4Policy -Name "PXEClient (BIOS x86 & x64)" -Description "Delivers the correct bootfile for BIOS machines" -Condition OR -VendorClass EQ,"PXEClient (BIOS x86 & x64)*" -ProcessingOrder 1 -Enabled $True -Confirm:$False
				}
				Catch{
				}
			}
			ElseIf($rtnDHCPPolicy -eq "UEFI 32-Bit DHCP Policy"){
				Try{
					Write-Output "Adding UEFI 32-Bit DHCP Policy..."
					Add-DhcpServerv4Policy -Name "UEFI 32-Bit DHCP Policy" -Description "Delivers the correct bootfile for (UEFI x86) machines" -Condition OR -VendorClass EQ,"PXEClient (UEFI x86)*" -ProcessingOrder 3 -Enabled $True -Confirm:$False
				}
				Catch{
				}
			}
			ElseIf($rtnDHCPPolicy -eq "UEFI 64-Bit DHCP Policy"){
				Try{
					Write-Output "Adding UEFI 64-Bit DHCP Policy..."
					Add-DhcpServerv4Policy -Name "UEFI 64-Bit DHCP Policy" -Description "Delivers the correct bootfile for (UEFI x64) machines" -Condition OR -VendorClass EQ,"PXEClient (UEFI x64)*" -ProcessingOrder 2 -Enabled $True -Confirm:$False
				}
				Catch{
				}
			}
			Else{
				Write-Output "Undefined policies cannot be added!"
			}
		}
	}
	Else{
		Write-Output "No Policies are required to be added."
	}
	
	#Restart-Service "DHCPServer"
}

Get-DHCPOptions
Get-DHCPClasses
Get-DHCPPolicies

Open in new window

0
 

Expert Comment

by:Hyoin Wang
Comment Utility
Many Thanks.

One more question:
I also deploy BIOS x86, but the policy covers (x86 & x64).  I will set up two 'Define Vendor Classes' for x86 and x64? But ASCII, could I set as PXEClient:Arch:00000 for both?
0
Free Tool: SSL Checker
LVL 10
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
1
 
LVL 66

Expert Comment

by:Jim Horn
Comment Utility
Nice work.  Voted Yes.
0
A Cisco router can be configured as a DHCP Server. There are advantages and disadvantages in making your Cisco router work as DHCP Server. Almost all the features for windows DHCP can be configured on Cisco-based DHCP server. Some of the features mentioned below at Setting IP Range, DNS, IP reservation and excluding IP address

Advantages: Best suited for satellite location or office connected through low bandwidth connectivity. Installing a Windows DHCP Server  or DHCP relay can consume the bandwidth. No addition hardware or software licensing required. Another advanthage is ease of configuration. It can be configured in two ways using the CLI (Command line interface) or SDM (Security Device Manager). SDM provide the GUI interface for your router. And the best part is that CISCO has also included debug commands in their IOS for troubleshooting.

Disadvantage: Will increase the load on the router, as it does the work of a router plus DHCP Server. But for a small network the load is negligible. Best suited for network that support 10 to 15 users.

Notice: The parts of the config/commands are open to variation (not specifically required keywords or commands).

Router> enable
Router# config t
Router(config)# ip dhcp pool LANPOOL
Router(dhcp-config)# network 192.168.1.0 255.255.255.0
Router(dhcp-config)# domain-name mycompany.com
Router(dhcp-config)# default-router 192.168.1.1
Router(dhcp-config)# dns-server 4.4.4.2
Router(dhcp-config)# 

Open in new window

2
Ever wondered why you had to use DHCP options (dhcp opt 60, 66 or 67) in order to use PXE?
Well, you don't!
1
 
LVL 17

Author Comment

by:vivigatt
Comment Utility
One side effect of having a PXE service (whether running on the same host as the DHCP service, thus requiring Dhcp Opt 60 to be set to PXEClient or on another host) is that you should NOT set DHCP opt 66 and 67.
When using a PXEService, dhcp options 66 and 67 are sent to the PXE clients by the PXE service itself, not by DHCP service.
0
 
LVL 17

Author Comment

by:vivigatt
Comment Utility
Of course, if your clients and servers are not on the same subnets, you need to set some kind of dhcp-relay (aka ip-helper or dhcp-forwarder) so that the dhcp broadcasts sent by your PXE clients are forwarded to the dhcp server on another subnet.
If your PXE server is not your dhcp server and is not in the same subnet as the PXE clients, then, in addition not to have any dhcp option 60 set to "PXEClient", you also must add the IP address of the PXE server to the list of IP addresses that get the dhcp broadcasts. In the Cisco world, it means adding the address of the PXE server to  "ip-helper" addresses on your routers or (Layer 3) switches. In that case, you would have both the DHCP server and PXE server(s) in ip-helper list of addresses
0

DHCP

10K

Solutions

14K

Contributors

The Dynamic Host Configuration Protocol (DHCP) is an auto configuration protocol used on IP networks and an extension of the Bootstrap Protocol. DHCP allows for computers to be configured automatically to communicate with each other over an IP network without the need for manual setup by a network administrator. The implementation of DHCP relies on a DHCP server to hand out network configuration information to DHCP-capable clients that request an IP address (and other information required or useful in communicating with other devices on an IP network). In addition to an IP address, common configuration information served over DHCP includes a default gateway, subnet mask and DNS sever(s).