How to change Hostname on Ubuntu
First find your current host name by typing:
hostname
Open /etc/hostname and change the host name specified there to the new host name.
sudo vi /etc/hostname
Now open /etc/hosts and locate the old host name in the file and change it to the new host name.
sudo vi /etc/hosts
Now restart hostname with:
sudo service hostname restart
How to propagate Hostname Change to DHCP Server and other machines
The chosen host name should be propagated to the DHCP server so that any other computer can refer to this computer by your new chosen hostname. To do that run the following commands:
sudo dhcclient -r ; sudo dhclient
Now you should be able to access this machine by its newly chosen host name from any other machine in the same network and served the same DHCP server.
An exception would be if a machine is configured statically or not configured to use the name server associated with this dhcp server.
Most routers today comes with DHCP server and an associated Name Server which can be configured as shown above.