Page 1 of 1

Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple VMs

Posted: 26. Nov 2020, 22:46
by Keagel
Hello,

I have been searching everywhere for a solution to this problem, and the only one that works is using sudo dhclient on every machine after it has booted which isn't very convenient.
The VMs are cloned with the "Generate new MAC addresses" option set. My DCHP server is correctly set as IPs are attributed to machines using the aforementioned command.
Creating a new VM and installing from scratch, its IP is properly attributed by the DHCP server.
Most other solutions point to changing the machine id, but this can only be done on Linux hosts and I am using Windows 10 Pro (2004).

Is there any actual way to fix this problem?

Thank you.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 27. Nov 2020, 01:41
by scottgus1
I have anecdotally seen some users' Linux VMs not respond to a change in IP address range when the Virtualbox network type is changed, and a reset of stored data about the network needed to be done inside the Linux VM OS. If I am not completely goofy in this assessment, it could be what you're facing. (I also am a Windows guy, so I don't know if this is true or how to properly handle it.)

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 27. Nov 2020, 12:53
by Keagel
scottgus1 wrote:a reset of stored data about the network needed to be done inside the Linux VM OS
How would one go about doing that?

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 28. Nov 2020, 00:35
by Keagel
It turns out changing the machine id actually fixed the problem. When cloning a VM, this id isn't changed and that causes all VMs with the same id to get the same IP from the DHCP server.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 28. Nov 2020, 03:59
by BillG
That makes sense. A clone is just that - an identical copy. That is why you need to change the MAC address.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 28. Nov 2020, 15:16
by scottgus1
Keagel wrote:It turns out changing the machine id actually fixed the problem.
Curious, here; how did you do this?

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 28. Nov 2020, 22:54
by Keagel
BillG wrote:That makes sense. A clone is just that - an identical copy. That is why you need to change the MAC address.
The MAC address wasn't the problem. When I cloned the VM, I actually choose the option to generate a new MAC address. I'm talking about the file /etc/machine-id.
scottgus1 wrote:
Keagel wrote:It turns out changing the machine id actually fixed the problem.
Curious, here; how did you do this?
I somehow can't find where I got the solution from, but it was actually very simple:

Code: Select all

sudo rm /etc/machine-id
sudo systemd-machine-id-setup
I simply ran the two commands on each cloned VM so each would get a unique machine id. I'm not sure why Ubuntu uses that instead of the MAC address.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 28. Nov 2020, 23:55
by scottgus1
Thanks for those commands!.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 29. Nov 2020, 00:56
by BillG
I would say it uses that as well as the MAC rather than instead of the MAC.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 29. Nov 2020, 01:06
by fth0
Keagel wrote:I'm not sure why Ubuntu uses that instead of the MAC address.
Maybe I can shed some light on the background:

In general, the DHCP Client Identifier option is used to identify the client. Since RFC 2132 (DHCP Options, 1997), the MAC address was often used for this. Since RFC 4361 (Node-specific Identifiers for DHCPv4, 2006), the DHCP Unique ID (DUID) was sometimes used instead, so that the Client Identifier is the same on multiple network interfaces and also when using IPv4 and IPv6. Since the current trend of MAC address randomization, the MAC address is sometimes used again for privacy reasons.

The Linux machine ID is used as the DUID when adhering to RFC 4361.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 29. Nov 2020, 01:36
by fth0
BillG wrote:I would say it uses that as well as the MAC rather than instead of the MAC.
Why do you think that?

If a DHCP request contains the DHCP Client Identifier option, the DHCP server must use that identifier to identify the client (and not the chaddr field, which contains the MAC address). The Linux DHCP client can be configured what to use for the DHCP Client Identifier option, but I think it's either the MAC address or the DUID (or something else), but not both.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 29. Nov 2020, 02:46
by BillG
Thanks for that.

Re: Cloning a VM and using a Host-only adapter with a DHCP server attributes the same IP to multiple

Posted: 30. Nov 2020, 00:38
by Keagel
fth0 wrote:
Keagel wrote:I'm not sure why Ubuntu uses that instead of the MAC address.
Maybe I can shed some light on the background:

In general, the DHCP Client Identifier option is used to identify the client. Since RFC 2132 (DHCP Options, 1997), the MAC address was often used for this. Since RFC 4361 (Node-specific Identifiers for DHCPv4, 2006), the DHCP Unique ID (DUID) was sometimes used instead, so that the Client Identifier is the same on multiple network interfaces and also when using IPv4 and IPv6. Since the current trend of MAC address randomization, the MAC address is sometimes used again for privacy reasons.

The Linux machine ID is used as the DUID when adhering to RFC 4361.
Thanks for the detailed explanation!