Configuring DHCP Services
Set up and manage DHCP services on Oracle Linux, with release-specific instructions for Oracle Linux 8 and 9 and Oracle Linux 10.
The Dynamic Host Configuration Protocol (DHCP) enables client systems to obtain network configuration information from a DHCP server each time they connect to the network. The DHCP server is configured with a range of IP addresses and other network configuration parameters that clients need.
When you configure an Oracle Linux system as a DHCP client, the client software contacts the DHCP server to obtain networking parameters. As DHCP is broadcast-based, the client must be on the same subnet as either a server or a relay agent. If a client can't be on the same subnet as the server, a DHCP relay agent can be used to pass DHCP messages between subnets.
The server provides a lease for the IP address that it assigns to a client. The client can request specific lease terms, such as the duration. If a client remains connected to the network, the client software automatically renews the lease before it expires. You can configure the DHCP server to provide the same IP address to a client, based on the MAC address of its network interface.
The advantages of using DHCP include the following:
-
Centralized management of IP addresses
-
Ease of adding new clients to a network
-
Reuse of IP addresses, reducing the total number of IP addresses that are required
-
Reconfiguration of the IP address space on the DHCP server without needing to reconfigure each client
Oracle Linux 10 uses the Kea DHCP server, while Oracle Linux 8 and Oracle Linux 9 use the legacy ISC DHCP server. Select the tab for the Oracle Linux release that you want to configure.
For more information about DHCP, see RFC 2131.
Use the ISC DHCP server on Oracle Linux 8 and Oracle Linux 9 to configure DHCPv4 and DHCPv6 services.
Oracle Linux 8 and Oracle Linux 9 provide the ISC DHCP server through the
dhcp-serverpackage. The following sections explain how to configure network interfaces, understand DHCP declarations, activate services, and recover from a corrupted lease database.-
dhcpd(8) -
dhcp-options(5)
Setting Up the Server's Network Interfaces
Configure the DHCP server service files so that the server listens on the correct IPv4 or IPv6 network interfaces.
Before proceeding to either of the following procedures, ensure that you meet the following requirements:
- You have the proper administrative privileges to configure DHCP.
- You have installed the
dhcp-serverpackage.If not, install the package with the following command:
sudo dnf install dhcp-server
By default, the
dhcpdservice processes requests on those network interfaces that connect them to subnets that are defined in the DHCP configuration file.Suppose that a DHCP server has multiple interfaces. Through its interface
enp0s1, the server is connected to the same subnet as the clients that the server is configured to serve. In this case,enp0s1must be set in the DHCP service to enable the server to monitor and process incoming requests on that interface.Use the following steps to configure the network interfaces.
-
For IPv4 networks, complete the following steps.
-
For IPv6 networks, complete the following steps.
Understanding DHCP Declarations
The way that DHCP provides services to its clients is defined through parameters and declarations in the
/etc/dhcp/dhcpd.conffile for IPv4 networks and/etc/dhcp/dhcpd6.conffile for IPv6 networks. The file can contain details such as client networks, address leases, IP address pools, and so on.Note
In a newly installed Oracle Linux system, both thedhcpd.confanddhcpd6.conffiles 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
- Subnet Declarations
- Shared-network Declarations
- Host Declarations
- Group 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 throughout the entire network:
- Domain name of the company network:
example.com. - Network's DNS servers:
dns1.example.comanddns2.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
authoritativeparameter 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 theauthoritativeparameter have priority to process requests over servers without the parameter.Subnet Declarations
A
subnetdeclaration 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
enp0s1interface is directly connected to the 192.0.2.0/24 network. - The systems in the 192.0.2.0/24 network are DHCP clients.
- This client subnet has the following topology:
- Subnet 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, 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; }In a DHCPv6 network environment, a
subnetdeclaration in thedhcpd6.conffile resembles 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-networkdeclaration if the DHCP server needs to provide services 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
subnetdeclaration refers to the server's own network and is outside theshared-networkscope. 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, thedhcpdservice doesn't start.On an IPv6 network environment, a
shared-networkdeclaration in thedhcpd6.conffile 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
hostdeclaration 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.130Important
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
hostdeclaration. Thus, the host name might change, but the client continues to receive services through the ethernet address.On an IPv6 network environment, a
hostdeclaration in thedhcpd6.conffile 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
groupdeclaration to apply the same parameters to multiple shared networks, subnets, and hosts all at the same time.Consider the following 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
groupdeclaration in thedhcpd6.conffile 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; }Activating the DHCP Services
Add DHCP configuration settings, then enable and start the DHCPv4 or DHCPv6 service.
All the DHCP services are defined in the server's
/etc/dhcp/dhcpd.confor/etc/dhcp/dhcpd6.conffile. To configure and then activate the configured services, follow these steps:- For IPv4 networks:
- Open the
/etc/dhcp/dhcpd.conffile. - Add parameters and declarations to the file.
For guidance, see Understanding DHCP Declarations or the comments and notes in the
/usr/share/doc/dhcp-server/dhcpd.conf.exampletemplate. - Optionally, set the
dhcpdservice to start automatically when the server reboots.sudo systemctl enable dhcpd - Start or restart the
dhcpdservice.sudo systemctl start dhcpd
- Open the
- For IPv6 networks:
- Open the
/etc/dhcp/dhcpd6.conffile. - Add parameters and declarations to the file.
For guidance, see Understanding DHCP Declarations or the comments and notes in the
/usr/share/doc/dhcp-server/dhcpd6.conf.exampletemplate. - Optionally, set the
dhcpd6service to start automatically when the server reboots.sudo systemctl enable dhcpd6 - Start or restart the
dhcpd6service.sudo systemctl start dhcpd6
- Open the
Recovering From a Corrupted Lease Database
Restore a corrupted DHCP lease database from the most recent backup lease file for DHCPv4 or DHCPv6.
Ensure that you have the required administrative privileges.
The
dhcpdservice maintains lease information, such as IP addresses, MAC addresses, and lease expiry times, in the following flat-file databases:- For DHCPv4:
/var/lib/dhcpd/dhcpd.leases. - For DHCPv6:
/var/lib/dhcpd/dhcpd6.leases.
To prevent the lease database files from becoming too large with stale data, the
dhcpdservice periodically regenerates the files through the following mechanism:- The service renames the existing lease files:
/var/lib/dhcpd/dhcpd.leasesis renamed to/var/lib/dhcpd/dhcpd.leases~./var/lib/dhcpd/dhcpd6.leasesis renamed to/var/lib/dhcpd/dhcpd6.leases~.
- The service re-creates brand new
dhcpd.leasesanddhcpd6.leasesfiles.
If a lease database file is corrupted, you need to restore the lease database from the last known backup of the database.
Typically, the most recent backup of a lease database is the
filename.leases~file.Note
A backup instance is a snapshot taken at a particular point in time, and therefore might not reflect the latest state of the system.-
For DHCPv4, complete the following steps.
-
For DHCPv6, complete the following steps.
-
Oracle Linux 10 replaces the legacy ISC DHCP server with Kea. This tab explains how to deploy Kea DHCPv4 and DHCPv6 services and highlights the client options available in this release.
Kea provides the DHCP server capability in Oracle Linux 10. Kea is modular, so you can run either the
kea-dhcp4orkea-dhcp6service, or both, depending on the network requirements.DHCP Server Software
Kea is the DHCP server software available in Oracle Linux 10. Kea replaces the ISC DHCP server that earlier releases of Oracle Linux provided. You can run either the
kea-dhcp4orkea-dhcp6service to provide DHCP on the network.For detailed configuration information beyond the examples in this topic, see the Kea Administrator Reference Manual.
DHCP Client Software
On an Oracle Linux 10 system operating as a DHCP client, NetworkManager handles DHCP requests. For information about DHCP configuration in NetworkManager, see the following manual pages:
NetworkManager(8)NetworkManager.conf(5)nm-settings-nmcli(5)
If you need a DHCP client daemon besides NetworkManager, the
dhcpcdsoftware package is available in the standard Oracle Linux 10 repositories.Setting Up a Kea DHCP Service
Before you install and configure a Kea DHCP service, verify that network interfaces that will listen for DHCP messages have static IP addresses.
Collect information about the system that will run the DHCP service and the network it will serve, such as interface names, default gateway or router addresses, name server IP addresses, and the intended subnet information and IP address ranges.
Complete the following steps to set up a Kea DHCP service. Configuring a Kea DHCPv4 Service
Complete the following steps to configure the kea-dhcp4service.Configuring a Kea DHCPv6 Service
Complete the following steps to configure the kea-dhcp6service.