20

I've cloned two vSphere VMs off of an Ubuntu 17.10 template. After boot, they both claim the same IP and fight for it (ssh connections break off as the IP switches between them).

The hostnames and MAC addresses are different between the two machines. dhclient correctly claims two separate IPs, but the resolver in use is systemd-networkd.

2 Answers 2

36

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, you need to generate a new /etc/machine-id. According to Is it OK to change /etc/machine-id?, the best way to do this is delete /etc/machine-id and reboot -- the boot process on most systems will generate a new /etc/machine-id automatically. Thanks to JdeBP and Andy Fraley for the additional information.

8
  • 3
    See unix.stackexchange.com/questions/402999 for why that does not work, what one actually has to do, and what state the machine has to be in to do it.
    – JdeBP
    Jan 24, 2018 at 13:13
  • Interesting. Good catch. +1 Jan 24, 2018 at 19:01
  • Wow. I've been banging my head on this one. I'm finally getting different IPs after following your suggestion. Although, onto my next issue. I cannot seem to ping the VMs from Host. Ugg! May 16, 2019 at 17:27
  • Nevermind. Problem solved. Thx for your post! May 16, 2019 at 18:20
  • 2
    On 20.04 you do not have to mess with /var/lib/dbus/machine-id, it's just a symlink to /etc/machine-id. The only thing you need to do is clear the contents of /etc/machine-id and reboot. Note that deleting the file breaks dhcp, instead clear the contents like > /etc/machine-id or truncate -s0 /etc/machine-id. Lastly, if you're making templates be sure to run cloud-init clean as well. Jan 4, 2022 at 2:36
18

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.
1
  • 2
    Great solution for a VM image.
    – Ed McMan
    Oct 10, 2019 at 14:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .