Cloned Linux VMs Get Same IP Address

PowerADM.com / Linux / Cloned Linux VMs Get Same IP Address

If you clone Linux virtual machines on your hypervisor (whether it be VMware ESXi, Hyper-V, or KVM/Proxmox), they will get the same IP address from the DHCP server after powering on, even if the VMs have different MAC addresses.

By default, the IP address in Linux is not bound to the MAC address, but to the Client ID. Until you change the machine-id, the cloned Linux virtual machines will receive the same IP address.

You can reset and regenerate the Client ID using the commands:

# rm -f /etc/machine-id
# dbus-uuidgen --ensure=/etc/machine-id

Your VM will get a new unique IP address from DHCP after the reboot. Thus, after cloning a Linux VM, you need to:

  1. Change the VM’s MAC address on the hypervisor;
  2. Change hostname # hostnamectl set-hostname newhostname
  3. Set a new hostname in /etc/hosts;
  4. Generate new machine-id.

If the netplan is enabled in your Linux distro (for example, Ubunu 18.04 and newer), you can change the binding of an IP address to a MAC address instead of a machine-id:

$ echo "send dhcp-client-identifier = hardware;" >>/etc/dhcp/dhclient.conf
$ rm /var/lib/dhcp/*
$ systemctl restart networking

Or use the dhcp-identifier: mac option in the netplan configuration file:

$ sudo nano /etc/netplan/myNetplan.yaml
network:
  ethernets:
    eth0:
      dhcp4: true
      dhcp-identifier: mac
  version: 2

Cloned Linux VM gets the same DHCP IP address

$ sudo netplan apply
Leave a Reply

Your email address will not be published. Required fields are marked *