Changing the hostname of a Debian server

I am doing web development using Python on a Linux environment and the plan for the final product is to be hosted at Linode.

As such, I want to setup a integration test environment that looks a little like the stuff at Linode and namely, the cheap VM specs that they offer. So I created a default VM in VirtualBox on my development workstation that looks like the Linode 512 VM. This default VM is a template whose purpose is to be cloned into other VMs and moved into the test server for execution. I will go into the software specs (what's installed in it) some other time.

Suffice it to say that moving the VM to the test server has 2 caveats that I haven't quite addressed in a graceful manner yet. One of the issues happens when I boot the new VM in the test server using the cloned VDI file and it loses the eth0 network interface. The other issue is related to the hostname of the VM and I will discuss this here today.

When I created the default VM on the workstation I chose the hostname change-hostname for it in an effort to thwart any inclinations of not changing such setting. I use debian-based operating systems exclusively and in the case of the VM, it is a Ubuntu server 10.04. In order to change the hostname in such machines, you need to follow these steps:

  1. Open the /etc/hostname file with your favorite editor. On Debian-based systems this file constains the hostname of the current machine.
  2. Delete the current name and change it to whatever you like
  3. Save the file and exit your editor
  4. Reset the hostname by running the following command:
    sudo /etc/init.d/hostname start
    

This is it... Pretty easy, but I want to automate it a little more; Too many steps to do manually.

Comments

Comments powered by Disqus