Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Motivation

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

Problem

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.

Facts

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

Question

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

1 Answer 1

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 192.168.2.5; option host-name "box1"; }

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

Limitations/comments:

  • 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.