Windows Server 2019 Automation with PowerShell Cookbook
上QQ阅读APP看书,第一时间看更新

Configuring DHCP scopes

In the previous recipe, Installing and authorizing a DHCP server, you installed and authorized a DHCP server on DC1.Reskit.Org. Before that server can begin to provide IP address configuration information to DHCP clients, you need to create a DHCP scope and DHCP options. A DHCP scope is a range of DHCP addresses that your DHCP server can give out (for a given IP subnet). DHCP options are specific configuration options your DHCP server provides, such as the IP address of the DNS server. DHCP options can be set at a scope level or at a server level, depending on the needs of your organization.

Getting ready

This recipe adds and configures a DHCP scope for your DHCP service on DC1. You installed the DHCP service and authorized it by completing the Installing and authorizing a DHCP server recipe.

How to do it...

  1. Create a new DHCP scope:
    $SHT = @{
      Name         = 'Reskit'
      StartRange   = '10.10.10.150'
      EndRange     = '10.10.10.199'
      SubnetMask   = '255.255.255.0'
      ComputerName = 'DC1.Reskit.Org'
    }
    Add-DhcpServerV4Scope @SHT
  2. Get scopes from the DHCP server:
    Get-DhcpServerv4Scope -ComputerName DC1.Reskit.Org
  3. Set DHCP option values for the DHCP server:
    $OHT = @{
      ComputerName = 'DC1.Reskit.Org'
      DnsDomain = 'Reskit.Org'
      DnsServer = '10.10.10.10'
    }
    Set-DhcpServerV4OptionValue @OHT
  4. Get the options set:
    Get-DhcpServerv4OptionValue -ComputerName DC1.Reskit.Org

How it works...

In this recipe, which uses the DHCP server module, you did some basic DHCP scope management. In particular, you created and updated a DHCP scope. In step 1, you created a new scope for the 10.10.10.0/24 subnet. There is no output from this step.

In step 2, you used the Get-DHCPServerV4Scope cmdlet to retrieve details of the scopes defined on DC1, which includes the scope that was set up in step 1. The output looks like this:

To enable a DHCP server to provide all the necessary IP configuration details to DHCP clients, you specified DHCP options. A DHCP option is a particular setting that the server can provide a client, for example, the IP address of a DNS server. You can set an option at the server level of a scope level, depending on your needs.

In step 3, you set two server-wide DHCP options, the DNS domain name (used in client DNS registrations), and the DNS server IP address. There is no output from this step.

In step 4, you used the Get-DHCPServerV4OptionValue cmdlet to see the server-wide DHCP options set on DC1, which looks like this:

There's more...

In step 1, you created the scope using the New-DHCPServerV4Scope cmdlet. This creates a DHCP scope for the 10.10.10.0/24 subnet, which contains a range of IP addresses that the server can provide to DHCP clients coming from this subnet (that is, 10.10.10.15010.10.10.199).

In step 3, you set an option and option value for the DNS server using the Set-DhcpServerV4OptionValue cmdlet. If you set a DNS server IP address, this cmdlet helpfully checks to see whether the IP address that's provided really is a DNS server (and returns an error message if so).

In this recipe, you created a simple scope for just one subnet that contained only two options. There is more complexity that you may encounter when scaling DHCP, including scope versus server options and client classes, which are outside the scope of this chapter. Nevertheless, the cmdlets used in this recipe form the core of what you might use in practice.