Understanding DHCP Declarations

The way the DHCP provides services to its clients is defined through parameters and declarations in the /etc/dhcp/dhcpd.conf file for IPv4 networks and /etc/dhcp/dhcpd6.conf file for IPv6 networks. The file would contain details such as client networks, address leases, IP address pools, and so on.

Note:

In a newly installed Oracle Linux system, both the dhcpd.conf and dhcpd6.conf files are empty. If the server is being configured for DHCP for the first time, then you can use the templates so you can be guided in configuring the files. Type one of the following commands:
  • For IPv4
    cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
  • For IPv6
    cp /usr/share/doc/dhcp-server/dhcpd6.conf.example /etc/dhcp/dhcpd6.conf

Then when you open either file, examples, and explanations are available for reference.

The information in the configuration file consists of a combination of the following declarations:

Global Settings

Global parameters define settings that apply to all networks that are supported or serviced by the DHCP server.

Consider the following settings that would globally apply through out the entire network:

  • Domain name of the company network: example.com.d
  • Network's DNS servers: dn1.example.com and dns2.example.com
  • Lease time assigned to all clients: 12 hours (43200 seconds)
  • Maximum lease time that can be assigned: 24 hours (86400 seconds)

In this case, you would configure the global settings in the configuration file as follows:

option domain-name "example.com";
default-lease-time 43200;
max-lease-time 86400;

authoritative;

The authoritative parameter identifies the server as an official or primary server for DHCP services. The parameter is typically used in a setup that has multiple DHCP servers. Servers with the authoritative parameter have priority to process requests over servers without the parameter.

Subnet Declarations

A subnet declaration provides details about a subnet to which the DHCP server is directly connected and where the systems in that subnet are also being served as clients.

Consider the following configuration of a DHCP server:

  • The server's enp0s1 interface is directly connected to the 192.0.2.0/24 network.
  • The systems in the 192.0.2.0/24 network are DHCP clients.
  • The topology of this client subnet is as follows:
    • Subnet's DNS server: 192.0.2.1.
    • Subnet gateway: 192.0.2.1.
    • Broadcast address: 192.0.2.255.
    • Address range for clients: 192.0.2.10 through 192.0.2.100.
    • Maximum lease time for each client: 86,400 seconds (1 day).
In this case, you would enter the following declaration in dhcp.conf:

subnet 192.0.2.0 netmask 255.255.255.0 {
  range 192.0.2.10 192.0.2.100;
  option domain-name-servers 192.0.2.1;
  option routers 192.0.2.1;
  option broadcast-address 192.0.2.255;
  max-lease-time 86400;
}

On an IPv6 network environment, a subnet declaration in the dhcpd6.conf file would resemble the following example:

subnet6 2001:db8:0:1::/64 {
  range6 2001:db8:0:1::20 2001:db8:0:1::100;
  option dhcp6.name-servers 2001:db8:0:1::1;
  max-lease-time 172800;
}

Shared-network Declarations

You define a shared-network declaration if the DHCP server needs to provide servers to clients in other subnets that aren't directly connected to the server.

Consider the following example, which expands but slightly differs from the scenario in the preceding section:

  • The DHCP server belongs to the 192.0.2.0/24 network but doesn't provide services to the systems in this network.
  • The server processes requests from clients in the following remote subnets:
    • 192.168.5.0/24.
    • 198.51.100.0/24.
  • The remote subnets share the same DNS server, but each subnet has its own router and IP address range.

In this case, you would enter the following declarations in dhcp.conf:

shared-network example {
 
  option domain-name-servers 192.168.2.1;
  ...

  subnet 192.168.5.0 netmask 255.255.255.0 {
    range 192.168.5.10 192.168.5.100;
    option routers 192.168.5.1;
  }

  subnet 198.51.100.0 netmask 255.255.255.0 {
    range 198.51.100.10 198.51.100.100;
    option routers 198.51.100.1;
  }
  ...
}

subnet 192.0.2.0 netmask 255.255.255.0 {
}

In the preceding example, the final subnet declaration refers to the server's own network and is outside the shared-network scope. The declaration is called an empty declaration because it defines the server's subnet. Because the server doesn't provide services to this subnet, no added entries are added, such as lease, address range, DNS information, and so on. Though empty, the declaration is required, otherwise, the dhcpd service doesn't start.

On an IPv6 network environment, a shared-network declaration in the dhcpd6.conf file would resemble the following example:

shared-network example {
  option domain-name-servers 2001:db8:0:1::1:1
  ...

  subnet6 2001:db8:0:1::1:0/120 {
    range6 2001:db8:0:1::1:20 2001:db8:0:1::1:100
  }

  subnet6 2001:db8:0:1::2:0/120 {
    range6 2001:db8:0:1::2:20 2001:db8:0:1::2:100
  }
  ...
}

subnet6 2001:db8:0:1::50:0/120 {
}

Host Declarations

You define a host declaration if a client needs to have a static IP address.

Consider the following example of a client printer in the server's 192.0.2.0/24 network. This time, the server provides DHCP services to the subnet.
  • Printer's MAC address: 52:54:00:72:2f:6e.
  • Printer's IP address: 192.0.2.130

    Important:

    A client's fixed IP address must be outside the pool of dynamic IP addresses distributed to other clients. Otherwise, address conflicts might occur.
In this case, you would enter the following declaration in dhcp.conf:
host printer.example.com {
	hardware ethernet 52:54:00:72:2f:6e;
	fixed-address 192.0.2.130; 
}

Systems are identified by the hardware ethernet address, and not the name in the host declaration. Thus, the host name might change, but the client continues to receive services through the ethernet address.

On an IPv6 network environment, a host declaration in the dhcpd6.conf file would resemble the following example:

host server.example.com {
	hardware ethernet 52:54:00:72:2f:6e;
	fixed-address6 2001:db8:0:1::200;
}

Group Declarations

You define a group declaration to apply the same parameters to multiple shared networks, subnets, and hosts all at the same time.

Consider this example:
  • The DHCP server belongs to and serves the subnet 192.0.2.0/24.
  • One client requires a fixed address, while the rest of the clients use dynamic IP addresses from the server.
  • All the clients use the same DNS server.

In this case, you would enter the following declaration in dhcp.conf:


group {
  option domain-name-servers 192.0.2.1;

  host server1.example.com {
    hardware ethernet 52:54:00:72:2f:6e;
    fixed-address 192.0.2.130;
  }

  subnet 192.0.2.0 netmask 255.255.255.0 {
  range 192.0.2.10 192.0.2.100;
  option routers 192.0.2.1;
  option broadcast-address 192.0.2.255;
  max-lease-time 86400;
  }
}

On an IPv6 network environment, a group declaration in the dhcpd6.conf file would resemble the following example:

group {
  option dhcp6.domain-search "example.com";

  host server1.example.com {
    hardware ethernet 52:54:00:72:2f:6e;
    fixed-address 2001:db8:0:1::200;
  }

  host server2.example.com {
    hardware ethernet 52:54:00:1b:f3:cf;
    fixed-address 2001:db8:0:1::ba3;
  }
}

subnet6 2001:db8:0:1::/64 {
  range6 2001:db8:0:1::20 2001:db8:0:1::100;
  option dhcp6.name-servers 2001:db8:0:1::1;
  max-lease-time 172800;
}