SkillPilotAI

PowerShell DhcpServer module (5/5)

The last part of the DhcpServer module covers the Set- cmdlets that change option values, option definitions, scopes, reservations, policies, the filter list, multicast scopes, failover and the IPv6 equivalents. The dnsmasq lab shows the key lesson: a server-side change reaches a client only on its next renew or new lease.

250.1 How a Set- change reaches the client

Option change arrives on renew
  1. 1.Admin PC runs Set-DhcpServerv4OptionValue -OptionId 6

  2. 2.On DHCP1 option 6 (DNS) = 10.0.0.53

  3. 3.Laptop1 still uses its old lease: DNS 10.0.0.10

  4. 4.Laptop1 sends DHCPREQUEST (renew)

  5. 5.DHCPACK carries DNS 10.0.0.53

  6. 6.Laptop1 now uses the new DNS

Clients renew at T1 = half the lease time; ipconfig /renew forces it on Windows

250.2 Set-DhcpServerv4OptionValue and option definitions

PowerShell
Set-DhcpServerv4OptionValue `  -DnsServer 192.168.1.2 `  -WinsServer 192.168.1.3 `  -DnsDomain "contoso.com" `  -Router 192.168.1.1 `  -Wpad "http://proxy.contoso.com/wpad.dat" Set-DhcpServerv4OptionValue -OptionId 6 `  -Value "192.168.1.1" Set-DhcpServerv4OptionDefinition `  -OptionId 3 -Name "Default Gateway" `  -Description "router set for the subnet"
LevelHow to target it
ServerNo level parameter
Scope-ScopeId 10.10.10.0
Reservation-ReservedIP 10.10.10.5
Policy-PolicyName "LabComputers"
Class-VendorClass "MSUCClient" / -UserClass
  • Named parameters (-DnsServer, -DnsDomain, -Router, -WinsServer, -Wpad) set common options; the generic form is -OptionId + -Value (6 = DNS server).
  • -Force skips the DNS server validation.
  • Option definition = name, type and default of an option ID; Set-DhcpServerv6OptionDefinition does the same for v6 (e.g. option 36).

250.3 Scope, reservation and policy

PowerShell
Set-DhcpServerv4Scope -ScopeId 10.10.10.0 `  -Name "Ext Lab Net VLAN100" `  -State Active -LeaseDuration 4.00:00:00 Set-DhcpServerv4Reservation `  -IPAddress 10.10.10.5 `  -Description "Fourth Floor Printer" `  -Name "printer.contoso.com" Set-DhcpServerv4Policy -Name "DevicesPolicy" `  -NewName TabletPolicy `  -Description "policy for tablet devices" `  -ProcessingOrder 4 -Enabled $FalseSet-DhcpServerv4Policy `  -Name "PhysicalMachinesPolicy" `  -Condition OR `  -MacAddress NE,00155D*,000569*Set-DhcpServerv4Policy -Name "TabletPolicy" `  -LeaseDuration 10
  • Scope: -StartRange/-EndRange change the pool; -Delay (ms) slows the secondary in a split scope; -ActivatePolicies, -SuperscopeName, -Type.
  • Reservation: change -Name/-Description; -ClientId sets a new MAC.
  • Policy: replacing the MAC condition keeps conditions on other fields, combined with OR; -LeaseDuration in days.

250.4 Filter list and multicast scope

Deny list on
  1. 1.Admin adds Laptop2's MAC to the deny list (Add-DhcpServerv4Filter)

  2. 2.Set-DhcpServerv4FilterList -Deny $True enables it

  3. 3.Laptop2 broadcasts DHCPDISCOVER

  4. 4.DHCP1 silently ignores it: no Offer

  5. 5.Laptop2 times out with no lease; Laptop1 still gets its lease

PowerShell
Set-DhcpServerv4FilterList `  -Allow $True -Deny $True Set-DhcpServerv4MulticastScope `  -Name "Multicast_VideoConference" `  -ExpiryTime "1/1/2014 0:01 AM" `  -LeaseDuration 40 -State Active `  -NewName `  "Multicast_VideoConferenceBuilding1"
  • FilterList has only -Allow and -Deny (lists on/off); the MACs come from Add-DhcpServerv4Filter.
  • Multicast scope: -LeaseDuration (default 30 days), -Ttl = routers it may cross, -NewName, -State.

250.5 Set-DhcpServerv4Failover

PowerShell
Set-DhcpServerv4Failover `  -Name "SFO-SIN-Failover" `  -LoadBalancePercent 70 `  -MaxClientLeadTime 2:00:00 `  -AutoStateTransition $True `  -StateSwitchInterval 2:00:00
PointLoad balanceHot standby
Who servesBoth servers share clientsActive serves, standby waits
Key parameter-LoadBalancePercent 70 (70/30)-ReservePercent 10 (free addresses kept for standby)
Switch mode-Mode LoadBalance-Mode HotStandby
Link downCOMMUNICATION INTERRUPTED -> PARTNER DOWN after StateSwitchIntervalSame
  • -PartnerDown moves the server straight to PARTNER DOWN; -SharedSecret authenticates messages (-Force skips its confirmation).

250.6 IPv6 Set- cmdlets

PowerShell
Set-DhcpServerv6Scope `  -Prefix 2001:4898:7020:1020:: `  -Name "Ext Lab Net VLAN100" -State ActiveSet-DhcpServerv6StatelessStore `  -Prefix 2001:4898:7020:1020:: `  -Enabled $True -PurgeInterval 2.00:00:00Set-DhcpServerv6OptionValue `  -Prefix 2001:4898:7020:1020:: `  -DnsServer 2001:4898:7020:1020::2 `  -DomainSearchList "contoso.com"Set-DhcpServerv6DnsSetting `  -Prefix 2001:4898:7020:1020:: `  -DynamicUpdates "OnClientRequest" `  -NameProtection $TrueSet-DhcpServerv6Binding -BindingState $True `  -InterfaceAlias "Wired Ethernet Connection"Set-DhcpServerv6Class `  -Name "Vendor Class for Printers" `  -Data "JetPrinters" -VendorId 100 `  -Type "Vendor"
  • v6 scope by -Prefix: lifetimes, -T1/-T2, -Preference; v6 reservation keyed by -ClientDuid + -Iaid.
  • Stateless store: entries with no request within -PurgeInterval are purged.
  • v6 option 23 = DNS server; -InfoRefreshTime limits how long stateless clients wait to refresh.
  • DNS setting: -DynamicUpdates Always|Never|OnClientRequest; -NameProtection uses DHCID records.
  • v6 class: -VendorId only for vendor classes.

250.7 Lab: change options, lease time, policy range

Output
interface=eth1port=0dhcp-range=tag:!printer,192.168.250.100,  192.168.250.150,255.255.255.0,1hdhcp-vendorclass=set:printer,LabPrinterdhcp-range=tag:printer,192.168.250.40,  192.168.250.49,255.255.255.0,30mdhcp-optsfile=/etc/n250-optsdhcp-hostsfile=/etc/n250-hosts# /etc/n250-opts (option 6 + option 15)option:dns-server,192.168.250.10option:domain-name,lab.example
Output
[client1]$ cat /tmp/udhcpc.log; ip -4 -br addr show eth0udhcpc: broadcasting select for 192.168.250.134, server 192.168.250.10udhcpc: lease of 192.168.250.134 obtained from 192.168.250.10, lease time 3600bound: ip=192.168.250.134 dns=192.168.250.10 domain=lab.example lease=3600 serverid=192.168.250.10[client2]$ udhcpc -i eth0 -n -q -t 3 -T 2 -V LabPrinter -s /tmp/hook.shudhcpc: lease of 192.168.250.40 obtained from 192.168.250.10, lease time 1800bound: ip=192.168.250.40 dns=192.168.250.10 domain=lab.example lease=1800 serverid=192.168.250.10
Terminal
# dhcp1: new option values (dns 192.168.250.53, sitea.example)pkill -HUP dnsmasq# laptop1: renewpkill -USR1 udhcpctail -n 4 /tmp/udhcpc.log
Output
udhcpc: sending renew to server 192.168.250.10udhcpc: lease of 192.168.250.134 obtained from 192.168.250.10, lease time 3600renew: ip=192.168.250.134 dns=192.168.250.53 domain=sitea.example lease=3600 serverid=192.168.250.10
  • Then the scope lease became 2h and the printer range .60-.69 with 10m, and dnsmasq was restarted.
  • laptop1's renew showed lease 7200 (like -LeaseDuration of Set-DhcpServerv4Scope); laptop2 got .60 with lease 600 (like Set-DhcpServerv4Policy).
Output
[client2]$ udhcpc -i eth0 -n -q -t 3 -T 2 -V LabPrinter -s /tmp/hook.shudhcpc: broadcasting select for 192.168.250.60, server 192.168.250.10udhcpc: lease of 192.168.250.60 obtained from 192.168.250.10, lease time 600bound: ip=192.168.250.60 dns=192.168.250.53 domain=sitea.example lease=600 serverid=192.168.250.10[server]$ cat /tmp/dnsmasq.leases1794250602 02:50:00:00:00:22 192.168.250.60 * 01:02:50:00:00:00:221794257186 02:50:00:00:00:11 192.168.250.134 laptop1 01:02:50:00:00:00:11

250.8 Lab: deny by MAC

Terminal
echo '02:50:00:00:00:22,ignore' \  > /etc/n250-hostspkill -HUP dnsmasqtime udhcpc -i eth0 -n -q -t 3 -T 2 \  -V LabPrinter -s /tmp/hook.shpkill -USR1 udhcpc
Output
[server]$ grep DHCP /tmp/dnsmasq.logdnsmasq-dhcp[137]: 4142408573 DHCPDISCOVER(eth1) 02:50:00:00:00:22 ignoreddnsmasq-dhcp[137]: 4142408573 DHCPDISCOVER(eth1) 02:50:00:00:00:22 ignoreddnsmasq-dhcp[137]: 4142408573 DHCPDISCOVER(eth1) 02:50:00:00:00:22 ignoreddnsmasq-dhcp[137]: 953451104 DHCPREQUEST(eth1) 192.168.250.134 02:50:00:00:00:11dnsmasq-dhcp[137]: 953451104 DHCPACK(eth1) 192.168.250.134 02:50:00:00:00:11 laptop1[client1]$ tail -n 4 /tmp/udhcpc.logrenew: ip=192.168.250.134 dns=192.168.250.53 domain=sitea.example lease=7200 serverid=192.168.250.10
  • laptop2 sent three Discovers, got no Offer and failed after a ~6 s timeout; allowed laptop1 renewed normally.

250.9 Common mistakes

  • Expecting every client to update instantly after a Set-: they update on the next renew (T1 = lease/2).
  • Making a big option change with a long lease: shorten the lease first so clients renew sooner.
  • Enabling the deny list with Set-DhcpServerv4FilterList but never adding the MAC with Add-DhcpServerv4Filter.
  • Giving -VendorId to a v6 user class.

250.10 Interview tips

  • DNS option changed but a laptop still has the old DNS: options arrive on renew or a new lease; ipconfig /renew forces it.
  • Load balance vs hot standby: -LoadBalancePercent (e.g. 70/30) vs -ReservePercent; link down -> PARTNER DOWN after StateSwitchInterval.
  • Option value levels: server, scope, reservation, policy, class.
  • DhcpServer series recap: Add- (1), v6 Add-/Backup/Export/Get- (2), Get-/Import/Remove- (3), Remove-/server Set- (4), Set- failover/filter/options (5).