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:
network:
version: 2
ethernets:
ens160:
dhcp4: true
match:
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?
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 usesystemd
(You can see an example of how this is done by looking atntp
'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
andcloud-init
. See Cloud-init nocloud set hostname dynamically from dhcp.