Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 3. Providing DHCP services
The dynamic host configuration protocol (DHCP) is a network protocol that automatically assigns IP information to clients. You can set up Kea to provide a DHCP server in your network.
3.1. The difference between static and dynamic IP addressing Copier lienLien copié sur presse-papiers!
To manage how devices receive their unique network addresses, administrators can select between two primary methods: static and dynamic IP addressing.
- Static IP addressing
When you assign a static IP address to a device, the address does not change over time unless you change it manually. Use static IP addressing if you want:
- To ensure network address consistency for servers such as DNS, and authentication servers.
- To use out-of-band management devices that work independently of other network infrastructure.
- Dynamic IP addressing
When you configure a device to use a dynamic IP address, the address can change over time. For this reason, dynamic addresses are typically used for devices that connect to the network occasionally because the IP address can be different after rebooting the host.
Dynamic IP addresses are more flexible, easier to set up, and administer. DHCP is a traditional method of dynamically assigning network configurations to hosts.
There is no strict rule defining when to use static or dynamic IP addresses. It depends on the user’s needs, preferences, and the network environment.
3.2. DHCP transaction phases Copier lienLien copié sur presse-papiers!
DHCP works in four phases: Discovery, Offer, Request, Acknowledgment, also called the DORA process. DHCP uses this process to provide IP addresses to clients.
- Discovery
- The DHCP client sends a message to discover the DHCP server in the network. This message is broadcasted at the network and data link layer.
- Offer
- The DHCP server receives messages from the client and offers an IP address to the DHCP client. This message is unicast at the data link layer but broadcast at the network layer.
- Request
- The DHCP client requests the DHCP server for the offered IP address. This message is unicast at the data link layer but broadcast at the network layer.
- Acknowledgment
- The DHCP server sends an acknowledgment to the DHCP client. This message is unicast at the data link layer but broadcast at the network layer. It is the final message of the DHCP DORA process.
3.3. Overview of using Kea for DHCPv4 and DHCPv6 Copier lienLien copié sur presse-papiers!
A key aspect of Kea’s design is that DHCPv4 and DHCPv6 are managed independently. Each protocol has its own configuration file and systemd service, giving you the flexibility to run a DHCPv4 server, a DHCPv6 server, or both to meet your network’s requirements.
For each protocol, Kea uses a separate configuration file and service:
- DHCPv4
-
Configuration file:
/etc/kea/kea-dhcp4.conf
-
Systemd service name:
kea-dhcp4
-
Configuration file:
- DHCPv6
-
Configuration file:
/etc/kea/kea-dhcp6.conf
-
Systemd service name:
kea-dhcp6
-
Configuration file:
3.4. The Kea lease database Copier lienLien copié sur presse-papiers!
A DHCP lease is the period for which Kea allocates a network address to a client. The lease databases contain information about the allocated leases, such as the IP address assigned to a media access control (MAC) address or the timestamp when the lease expires.
All timestamps in the lease databases are in Coordinated Universal Time (UTC).
Kea supports the following lease backends:
memfile
(default)A text-based file stored on the disk. By default, Kea stores the DHCP leases in the following files:
-
For DHCPv4:
/var/lib/kea/kea-leases4.csv
For DHCPv6:
/var/lib/kea/kea-leases6.csv
WarningManually updating the files can cause inconsistencies and file corruption. For performance reasons, Kea stores the lease data in memory and does not monitor the lease files during runtime. Manual edits can be overridden the next time Kea updates the files.
-
For DHCPv4:
mysql
- A MySQL database backend.
pgsql
- A PostgreSQL database backend.
For example, Kea updates the lease database in the following cases:
- On lease updates
- On graceful shutdown
- During periodic lease file cleanup (LFC) processes
- By requests through the API
3.5. Setting up a Kea DHCP server Copier lienLien copié sur presse-papiers!
Kea is a modern, high-performance DHCP server with a modular design. Use a DHCP server to automatically assign IP addresses and other network settings to client devices. This eliminates the error-prone task of manual configuration.
Prerequisites
-
The
kea
package is installed. -
You are logged in as the
root
user.
Procedure
If you are configuring an IPv4 network:
Edit the
/etc/kea/kea-dhcp4.conf
file, and use the following configuration:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example configures Kea to serve two subnets: one directly connected to the server and a remote one that uses a DHCP relay agent.
The settings specified in the example include the following:
interfaces
- Defines the network interfaces on which Kea listens for DHCP requests. If a subnet is not directly connected to the server, ensure that you list the interface through which the subnet can be reached.
id
- Defines a unique integer for the subnet. This is required if you define more than one subnet.
subnet
- Defines the subnet in Classless Inter-Domain Routing (CIDR) format.
pools
- Defines the IP address ranges from which Kea can assign addresses to clients.
option-data
- Defines DHCP options sent to clients, such as the default gateway and DNS servers. Per-subnet option-data settings override global settings.
relay
- Defines the IP addresses of DHCP relay agents. While this setting is optional for remote subnets, it improves the security to limit forwarded requests to trusted agents. Do not use this parameter for directly-connected subnets.
Verify the syntax of the configuration file:
kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
# kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Update the
firewalld
rules to allow incoming DHCPv4 traffic:firewall-cmd --permanent --add-service=dhcp firewall-cmd --reload
# firewall-cmd --permanent --add-service=dhcp # firewall-cmd --reload
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enable and start the service:
systemctl enable --now kea-dhcp4
# systemctl enable --now kea-dhcp4
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If you are configuring an IPv6 network:
Edit the
/etc/kea/kea-dhcp6.conf
file, and use the following configuration:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example configures Kea to serve two subnets: one directly connected to the server and a remote one that uses a DHCP relay agent.
Verify the syntax of the configuration file:
kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
# kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Update the
firewalld
rules to allow incoming DHCPv6 traffic:firewall-cmd --permanent --add-service=dhcpv6 firewall-cmd --reload
# firewall-cmd --permanent --add-service=dhcpv6 # firewall-cmd --reload
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enable and start the service:
systemctl enable --now kea-dhcp6
# systemctl enable --now kea-dhcp6
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
-
Configure a network connection with DHCP on a client. See Configuring an Ethernet connection by using
nmcli
. - Connect the client to the network.
Check if the client received an IP address from the DHCP server:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Troubleshooting
Check on which IPv4 and IPv6 addresses Kea is listening:
ss -lunp | grep -E ':(67|547)'
# ss -lunp | grep -E ':(67|547)'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If Kea does not listen on all interfaces you configured, check the
interfaces-config
setting in the Kea configuration files.
Next steps
3.6. Configuring loggers in Kea Copier lienLien copié sur presse-papiers!
If you want to customize log settings, such as the severity level, configure loggers
in Kea.
By default, Kea writes log messages to:
- The systemd journal
-
The
/var/log/messages
files, if thersyslogd
service is running
Prerequisites
-
The
kea-dhcp4
andkea-dhcp6
services are configured and running. -
You are logged in as the
root
user.
Procedure
If you are configuring an IPv4 network:
Edit the
/etc/kea/kea-dhcp4.conf
file, and add theloggers
configuration to theDhcp4
parameter. For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The settings specified in the example are:
name
-
Defines the name of the binary the
logger
settings apply to. output
-
Sets the log file name in the
/var/lib/kea/
directory. maxsize
-
Sets the maximum size of the log file before Kea rotates it. The default value is
10240000
bytes. maxver
-
Sets the maximum number of rotated versions Kea will keep. Note that a
maxsize
value less than204800
bytes disables rotation. severity
-
Specifies the category of messages logged. You can set one of the following values:
NONE
,FATAL
,ERROR
,WARN
,INFO
, andDEBUG
. Kea logs only messages of the configured severity and above.
Verify the syntax of the configuration file:
kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
# kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Restart the
kea-dhcp4
service:systemctl restart kea-dhcp4
# systemctl restart kea-dhcp4
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If you are configuring an IPv6 network:
Edit the
/etc/kea/kea-dhcp6.conf
file, and add theloggers
configuration to theDhcp6
parameter, for example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the syntax of the configuration file:
kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
# kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Restart the
kea-dhcp6
service:systemctl restart kea-dhcp6
# systemctl restart kea-dhcp6
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
- Monitor the log file you have configured to verify that it displays messages of the expected severity.
3.7. Assigning a static address to a host by using DHCP Copier lienLien copié sur presse-papiers!
In Kea, you can use a reservation inside a subnet definition to assign a fixed IP address to a media access control (MAC), a DHCP unique identifier (DUID), or other identifiers.
For example, use this method to always assign the same IP address to a server or network device.
Prerequisites
-
The
kea-dhcp4
andkea-dhcp6
services are configured and running. -
You are logged in as the
root
user.
Procedure
If you are configuring an IPv4 network:
Edit the
/etc/kea/kea-dhcp4.conf
file, and add a reservation to thesubnet4
parameter:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example configures Kea to always assign the
192.0.2.130
IP address to the host with the52:54:00:72:2f:6e
MAC address.For further examples, see the
/usr/share/doc/kea/examples/kea4/reservations.json
file provided by thekea-doc
package.Verify the syntax of the configuration file:
kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
# kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Restart the
kea-dhcp4
service:systemctl restart kea-dhcp4
# systemctl restart kea-dhcp4
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If you are configuring an IPv6 network:
Edit the
/etc/kea/kea-dhcp6.conf
file, and add a reservation to thesubnet6
parameter:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example configures Kea to always assign the
2001:db8:0:1::99
IP address to the host with the52:54:00:72:2f:6e
MAC address.For further examples, see the
/usr/share/doc/kea/examples/kea6/reservations.json
file provided by thekea-doc
package.Verify the syntax of the configuration file:
kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
# kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Restart the
kea-dhcp6
service:systemctl restart kea-dhcp6
# systemctl restart kea-dhcp6
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.8. Classifying clients in Kea Copier lienLien copié sur presse-papiers!
Kea client classes provide a mechanism for grouping clients based on specific criteria, allowing for granular control over network configuration. You can use this feature to apply special processing rules or assign different DHCP options to clients.
You can create a client class that assigns Voice over IP (VoIP) devices to a specific IP pool to ensures that VoIP phones get different IP addresses than other devices on the network. For example, in IPv4 networks, you can use a substring
expression to test for the first 3 octets of their media access control (MAC) address. In IPv6 networks where the MAC address is not a reliable indicator, you can test for a substring of the DHCPv6 vendor class option.
Prerequisites
-
The
kea-dhcp4
andkea-dhcp6
services are configured and running. -
You are logged in as the
root
user.
Procedure
If you are configuring an IPv4 network:
Edit the
/etc/kea/kea-dhcp4.conf
file, and make the following changes:Add the following client classes to the
Dhcp4
parameter:Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, devices with a MAC address starting with
52:54:00
match theVoIP-Phones
client class. Devices that do not match the rule are assigned to theOthers
client class.Assign the client classes to your
pool
definitions:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Depending on which client class a host matches, Kea assigns an IP from the corresponding pool.
Verify the syntax of the configuration file:
kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
# kea-dhcp4 -t /etc/kea/kea-dhcp4.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Restart the
kea-dhcp4
service:systemctl restart kea-dhcp4
# systemctl restart kea-dhcp4
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If you are configuring an IPv6 network:
Edit the
/etc/kea/kea-dhcp6.conf
file, and make the following changes:Add the following client classes to the
Dhcp6
parameter:Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, devices that send a DHCPv6 vendor class option (option 16) where the hexadecimal value begins with
00000009
match theVoIP-Phones
client class. Devices that do not match the rule are assigned to theOthers
client class.Assign the client classes to your
pool
definitions:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Depending on which client class a host matches, Kea assigns an IP from the corresponding pool.
Verify the syntax of the configuration file:
kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
# kea-dhcp6 -t /etc/kea/kea-dhcp6.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns
Syntax check failed
, fix the errors shown in the report.Restart the
kea-dhcp6
service:systemctl restart kea-dhcp6
# systemctl restart kea-dhcp6
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
- Connect clients that match the rules in the client classes and verify that Kea assigned an IP from the associated pool.
3.9. Comparison of DHCPv6 to radvd Copier lienLien copié sur presse-papiers!
In an IPv6 network, only router advertisement messages provide information about an IPv6 default gateway. If you want to use DHCPv6 in subnets that require a default gateway setting, you must additionally configure a router advertisement service, such as Router Advertisement Daemon (radvd
).
The radvd
service uses flags in router advertisement packets to announce the availability of a DHCPv6 server.
The following table compares features of DHCPv6 and radvd
:
DHCPv6 | radvd | |
---|---|---|
Provides information about the default gateway | no | yes |
Guarantees random addresses to protect privacy | yes | no |
Sends further network configuration options | yes | no |
Maps media access control (MAC) addresses to IPv6 addresses | yes | no |
3.10. Configuring the radvd service for IPv6 routers Copier lienLien copié sur presse-papiers!
The router advertisement daemon (radvd
) sends router advertisement messages that are required for IPv6 stateless autoconfiguration. This enables users to automatically configure their addresses, settings, routes, and to choose a default router based on these advertisements.
You can only set /64
prefixes in the radvd
service. To use other prefixes, use DHCPv6.
Prerequisites
-
You are logged in as the
root
user.
Procedure
Install the
radvd
package:dnf install radvd
# dnf install radvd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Edit the
/etc/radvd.conf
file, and add the following configuration:Copy to Clipboard Copied! Toggle word wrap Toggle overflow These settings configure
radvd
to send router advertisement messages on theenp1s0
device for the2001:db8:0:1::/64
subnet. TheAdvManagedFlag on
setting defines that the client should receive the IP address from a DHCP server, and theAdvOtherConfigFlag
parameter set toon
defines that clients should receive non-address information from the DHCP server as well.For further details, see the
radvd.conf(5)
man page on your system and the/usr/share/doc/radvd/radvd.conf.example
file.Optional: Configure that
radvd
automatically starts when the system boots:systemctl enable radvd
# systemctl enable radvd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
radvd
service:systemctl start radvd
# systemctl start radvd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the content of router advertisement packages and the configured values
radvd
sends:radvdump
# radvdump
Copy to Clipboard Copied! Toggle word wrap Toggle overflow