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

Discussions related to using VirtualBox on Windows hosts.
Post Reply
Keagel
Posts: 5
Joined: 26. Nov 2020, 22:29

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

Post 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.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

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

Post 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.)
Keagel
Posts: 5
Joined: 26. Nov 2020, 22:29

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

Post 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?
Keagel
Posts: 5
Joined: 26. Nov 2020, 22:29

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

Post 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.
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

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

Post by BillG »

That makes sense. A clone is just that - an identical copy. That is why you need to change the MAC address.
Bill
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

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

Post by scottgus1 »

Keagel wrote:It turns out changing the machine id actually fixed the problem.
Curious, here; how did you do this?
Keagel
Posts: 5
Joined: 26. Nov 2020, 22:29

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

Post 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.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

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

Post by scottgus1 »

Thanks for those commands!.
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

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

Post by BillG »

I would say it uses that as well as the MAC rather than instead of the MAC.
Bill
fth0
Volunteer
Posts: 5690
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows 10, ...
Location: Germany

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

Post 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.
fth0
Volunteer
Posts: 5690
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows 10, ...
Location: Germany

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

Post 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.
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

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

Post by BillG »

Thanks for that.
Bill
Keagel
Posts: 5
Joined: 26. Nov 2020, 22:29

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

Post 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!
Post Reply