Many things have changed from the oh so abundant 18.04 server and there are a few surprises that one needs to be aware of. One thing that has changed is that changing the MAC address no longer changes the ID when the server requests a new IP from a DHCP server.
This means that cloning a server into a new server they will start competing for the same IP address if they are on the same network so there are a few things you need to do before you deploy the new close.
Fix the IP address of the clone
- First release the DHCP address the machine has by issuing the command ”dhcpd -r” which should take care of this.
- Change the mac address, if you are using bridged network in particular there should not be two network interfaces on the same segment with the same MAC address. This is done in the virtual machine software.
- Change the machine-id of the clone. This is done by deleting the file /etc/machine-id and then running the script systemd-machine-id-setup which will create a new one.
- Optional: If you would like the system to change the network ID when you change mac address on the NIC then you need to change the following file(s) /etc/netplan/*.yaml and edit this to insert under each of the network interfaces you want to use MAC address as their ID ”dhcp-identifier: mac” then run sudo netplan apply.
Now shutdown the host, change the networking to whatever is needed (bridged most usually) and then restart the system and it should now be assigned a new IP address.
Fix the SSH keys of the clone
Next step is of course to change the cloes SSH keys which is done by deleting the keys in /etc/ssh by issuing the command ”rm /etc/ssh/ssh_host_*” which would delete all of them.
Then regenerate new keys from using the command ”dpkg-reconfigure openssh-server” which will generate all needed keys as if it was fresly installed.