Set Hostname

The hostname of a virtual machine can be changed on startup. The name of the virtual domain is passed in a smbios string and can be used to rename.


This feature is available from release 0.3.4 and requires libvirt-4.6.


  • Ravada: 0.3.4

  • libvirt: 4.6


This feature has been reported to work with these Linux distributions. Any other distribution with libvirt 4.6 or bigger will work too. Please report if you successfully tested it.

Supported distributions:

  • Ubuntu 18.10


The virtual machine name can be read with dmidecode

dmidecode | grep hostname | awk -F: '{ print $3}'

To set the hostname you must create a script that runs on startup, this one line should be enough for most cases:

hostname `dmidecode | grep hostname | awk -F: '{ print $3}'`

Some tools may read the hostname from the config file, set it like this:

dmidecode | grep hostname | awk -F: '{ print $3}' | sed -e 's/^ //' > /etc/hostname


If your system supports systemd this script will set the virtual machine name as the hostname on startup. Put the service file in /lib/systemd/system/sethostname.service:


Description=Set Hostname


This is the script that is launched by the service, it should be in /usr/local/bin/ as specified in the previous file.

date >> /var/log/set_hostname.log
hostname=`/usr/sbin/dmidecode | grep hostname | awk '{ print $4}'`
if [ ! -z "$hostname" ]; then
	/bin/hostname $hostname
	/bin/hostname > /etc/hostname
	echo "Found hostname $hostname in dmidecode " >> /var/log/set_hostname.log
	echo "Not found hostname in dmidecode " >> /var/log/set_hostname.log
	/usr/sbin/dmidecode >> /var/log/set_hostname.log

Type this so the script is executed on startup:

sudo chmod +x /usr/local/bin/
sudo systemctl enable sethostname

Reboot and check if the hostname is applied. You should find a log file at /var/log/set_hostname.log.


If you Linux system supports rc.local just add this lines to it and the hostname will be updated on boot:

hostname `dmidecode | grep hostname | awk -F: '{ print $3}'`
hostname > /etc/hostname


SMBios information is available in Windows too. The data is stored in the registry and also can be shown with a tool called WMI.

Contributed information would be appreciated.