Ubuntu 18.04 Server
When using libvirt / Virtual media manager for cloning a KVM based Ubuntu Server virtual machine, we should change the hostname of the cloned VM after first reboot. Here is the code to accomplish this
sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/g' /etc/cloud/cloud.cfg
sudo hostnamectl set-hostname NewHostName
Code language: JavaScript (javascript)
Reboot
sudo reboot -h
Check Hostname
hostnamectl
Ubuntu 18.04 Desktop
On Ubuntu 18.04 desktop, cloud-init is not utilized. So the code on Ubuntu Desktop is simply –
sudo sed -i 's/OriginalHostName/NewHostName/g' /etc/hostname
hostname
sudo hostnamectl set-hostname NewHostName
sudo reboot
hostnamectl
sudo reboot -h
Code language: JavaScript (javascript)
Ubuntu 19.04 Desktop
sudo hostnamectl set-hostname NewHostName
sudo reboot
hostnamectl
Code language: JavaScript (javascript)