I'm trying to figure out how to configure my DHCP client on Ubuntu server 18.04.

I have the following netplan configuration, coming from cloud-init:

    version: 2
            dhcp4: true
                macaddress: 02:dc:01:00:38:4c
            set-name: ens160

This seems to properly configure my network interface with an ip address, dns, default gateway and search domain. However, I'm wondering how to obtain a hostname from DHCP. I've been looking into dhclient which provides some convenient hooks that I can use, however it doesn't appear that dhclient hooks are being called. I've noticed that cloud-init calls dhclient as per the logs, but as some sort of sandboxed version, which seems to ignore the hooks.

I've also noticed that systemd-networkd reports some DHCP activity regarding to DHCP leases.

Could someone shed some light into the process?

  • Our DHCP server was expecting a particular MAC address : dhcp-identifier: mac at the same level than dhcp4solved my problem. Might not be yours but it might help others. – JB. With Monica. Dec 6 '19 at 13:13

I did more digging on this, so leaving some info for others.

Looks like Ubuntu 18.04 doesn't use dhclient anymore, which was called in daemon mode by ifupdown. Instead, systemd-networkd takes care of all things DHCP. In order to create DHCP client hooks, we must now use systemd (You can see an example of how this is done by looking at ntp's files: /lib/systemd/system/ntp-systemd-netif.{path|service}).

As mentioned in the question, cloud-init does call dhclient in a sandboxed more, but only for some particular clouds.

In terms of setting the hostname, there may be conflicts between systemd-networkd and cloud-init. See Cloud-init nocloud set hostname dynamically from dhcp.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.