Configuring Ubuntu Server 22.04 to Use MAC Address for DHCP Client ID

When setting up an Ubuntu Server 22.04, especially in a headless environment, systemd-networkd often handles network configurations. By default, systemd-networkd uses a DUID (DHCP Unique Identifier) as its DHCP client identifier, which might not be compatible with all DHCP servers that expect a MAC address. This guide will walk you through configuring your Ubuntu Server 22.04 to use its MAC address as the DHCP client identifier for IPv4 using systemd-networkd.

First, ensure that systemd-networkd is indeed managing your network. You can verify this by running the following command in your terminal:

systemctl status systemd-networkd

If systemd-networkd is active, you can proceed to configure it. The configuration for systemd-networkd is done through .network files, typically located in /etc/systemd/network/. Let’s create a configuration file, for example, 01-ethernet.network, to apply settings to Ethernet interfaces:

[Match]
Name=*
Type=ether

[Network]
DHCP=ipv4

[DHCPv4]
ClientIdentifier=mac

In this configuration:

  • [Match] Name=* Type=ether ensures that this configuration applies to all Ethernet interfaces. You can adjust the Name= to target specific interfaces (e.g., Name=enp0s3). For wireless interfaces, you would use Type=wlan. To see the types of your interfaces, use the command networkctl -a.
  • [Network] DHCP=ipv4 enables DHCP for IPv4 on the matched interfaces. You can also set DHCP=yes for both IPv4 and IPv6, or DHCP=no to disable DHCP.
  • [DHCPv4] ClientIdentifier=mac is the crucial part. It explicitly sets the DHCP client identifier to the MAC address for IPv4.

While you might have configured Netplan with dhcp-identifier: mac in your YAML configuration files, it’s important to note that this setting might not always be sufficient for systemd-networkd. Directly configuring systemd-networkd with a .network file as described ensures that the MAC address is used as the DHCP client identifier.

For more advanced configurations and options available for systemd-networkd, you can refer to the official documentation. The systemd.network man page provides comprehensive details on all available settings and options. You can access it online or directly on your Ubuntu server using man systemd.network.

By configuring ClientIdentifier=mac in your systemd-networkd configuration file, you ensure better compatibility with DHCP servers that rely on MAC addresses for client identification, streamlining network management on your Ubuntu Server 22.04.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *