set_hostname.rst 1.14 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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.

Linux
-----

The virtual machine name can be read with dmidecode

.. prompt:: bash $

    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:

.. prompt:: bash $

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

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

.. prompt:: bash $

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


rc.local
~~~~~~~~

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

Windows
-------

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.