Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I have to manage a lot of virtual machines that I create by copying a template (VmWare image).


Now I have the problem that in the template the file /etc/hostname contains a given name that I want to change for each copy of the template.


The network interface is configured by DHCP. DNS entries exist. The system is a Ubuntu 9.10 server.


I wonder if I can configure the template so that on startup it sets its hostname according to its DNS name.

I could create an init script that parses the IP address, makes a DNS lookup and sets the hostname accordingly.

But is there an easier way?

share|improve this question

If the machine already has an IP address, it's a bad idea to attempt changing the hostname. Defining the hostname should only occur during system/VM boot.

The good news is: if the VMs are Linux-based[1], and have unique MAC addresses[2], it's possible to set the hostname via DHCP. The applicable section in dhcpd.conf should look like a variant of:

host box1 { hardware ethernet 00:AC:08:22:FC:B2; fixed-address; option host-name "box1"; }

Recommend taking a look at the docs for whichever DHCP server you're running.


  • You may also want to define "option domain-name"
  • can only be set during booting of the VM (overriding a system's existing hostname causes problems)
  • you may need to define "request hostname" in the dhclient config
  • DHCP server must be in the same network "segment" as the client (i.e., MAC addresses for remote machines are not "visible")

[1] My last known was that Windows didn't support this. However, it's been awhile, so this may no longer be an accurate statement.

[2] Assumed to be true as VMware will not run multiple VMs with the same MAC address.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .