Dynamic hostname for VM’s generated from Virtualbox

I am currently working on dynamic environment provisioning for baremetal and hypervisors. Going through my notes, I found the following post, it was obviously copied from somewhere and i don’t have the URL for it. I am posting it here again for future reference as i think it is a very clever idea.

These scripts are used for simple management of hostnames for several VirtualBox VMs comprising a test or sandbox environment on your local machine.
Architecture:

  • Each VM is configured to use bridged network adapter, so all VMs and the host can see each other
  • A script is installed in each VM to run on post-ifup, which grabs VM’s IP, puts “$IP $desired-hostname $desired-fully-qualified-hostname” into /etc/hosts, changes hostname correspondingly, and puts VM’s hostname and fq-hostname into VM’s properties
  • A script is used on the host machine, which loops through running VMs, and updates /etc/hosts on the host machine and on the VMs

Setup:

1. On CentOS/RedHat VM:
1.1. put “ifup-local.sh” to /etc/sysconfig/network-scripts directory
1.2. change HN and FQHN variable values to desired hostname and fully qualified hostname for this VM
1.3. make soft link to the file from /sbin: ln -s /etc/sysconfig/network-scripts/ifup-local.sh /sbin/ifup-local
2. On the host use update-vms script to update VMs and host’s /etc/hosts files when VMs are started, stopped, or network configuration (IPs) is updated

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">