Why are my cloned linux VMs fighting for the same IP
systemd-networkd
uses a different method to generate the DUID than dhclient
. dhclient
by default uses the link-layer address while systemd-networkd
uses the contents of /etc/machine-id
. Since the VMs were cloned, they have the same machine-id
and the DHCP server returns the same IP for both.
To fix, replace the contents of one or both of /etc/machine-id
. This can be anything, but deleting the file and running systemd-machine-id-setup
will create a random machine-id
in the same way done on machine setup.
What about netplan configuration? There is an option dhcp-configuration
that can be used as follows (excerpt from netplan examples):
network:
version: 2
ethernets:
enp3s0:
dhcp4: yes
dhcp-identifier: mac
by default it is using machine-id, but by changing this feature we can 'force' it not to.
Excerpt from manpages/netplan, giving more insights:
dhcp-identifier (scalar)
When set to `mac'; pass that setting over to systemd-networkd to use the device's
MAC address as a unique identifier rather than a RFC4361-compliant Client ID. This
has no effect when NetworkManager is used as a renderer.