it-artikel:linux:cave-cloned-vms-of-ubuntu-20.04-server-or-desktop-all-keep-same-ip-address-even-when-mac-had-changed

CAVE cloning VMs of UBUNTU 20.04 Server or Desktop can result in networking problems. Same IP address in every cloned VM, even if MAC address has been changed

Problem:

Using virtualisation (VMs) like Virtualbox, KVM etc, people sometimes “clone” existing UBUNTU 20.04 Server VMs and later experience a problem in DHCP enabled networks. These VMs seem to clinge to their former IP address, not requesting unique addresses. Thus having problems with networking. That even happends with changed/unique MAC addresses.

That behaviour may affect even earlier UBUNTU versions and some DEBIAN based distros as well. It does NOT affect manual/fixed/static network configurations.

Cause:

The problem can be caused by a unfortune combination of DHCP Client and DHCP Server in the network. While historically DHCP servers are used to hand out unique IP adresses to every new MAC address, a client or server today “can” request/send also other client identification information as well. Like “machine id”. So a DHCP client and/or server may hand out “the same IP address” to different network interfaces (different MAC addresses) IF those DHCP clients present themselfs with the same machine (installation) ID.

Since the VMs in these cases has been cloned, all these VMs contain the same machine id.

You can check the machine ID of your UBUNTU installation like that:

cat /etc/machine-id 
cat /var/lib/dbus/machine-id

As you can see here, there may even be more that one place where your machine id/installation id has been placed.

Solution:

As always there are more than just one solution to any problem. Some people seem to have success by deleting or replacing the IDs in those files. However, if you dont care for unique machine IDs and just want to have the DHCP client work again as once intended, you can just tell the DHCP client what unique ID to use to request a new IP address.

Since for UBUNTU Server these days “netplan” is the default network manager i'll show how i did it on my VMs:

  1. Make sure your VMs MAC addresses are unique all over your network.
  2. Optional: If you want to change your hostname
    # set new fqdn/hostname
    hostnamectl set-hostname newFullQualifiedHostname.lan
    
    # update /etc/hosts with that new hostname (full + short)
    sed -i "s/\(^127.0.1.1\s\).*/\1$(hostname -f)\t$(hostname -s)/" /etc/hosts
  3. Change your default (or manual) “netplan” IPv4 DHCP networking configuration as shown here. Add the dhcp-identifier: mac line: :!: Watch the indentation! Its important with yaml files!:
    cat << EOF > /etc/netplan/00-installer-config.yaml
    network:
      ethernets:
        enp0s3:
          dhcp4: true
          dhcp-identifier: mac
      version: 2
    EOF
    netplan apply
    reboot
  4. Of course do that on all your cloned VMs. Fixed the problem within my lab.
it-artikel/linux/cave-cloned-vms-of-ubuntu-20.04-server-or-desktop-all-keep-same-ip-address-even-when-mac-had-changed.txt · Last modified: 2022-08-31 12:30 by 127.0.0.1