Change the oldhostname to a newhostname in the following files:
sudo nano -w /etc/hosts
sudo nano -w /etc/hostname
After done, changing the /etc/hostname and /etc/hosts, you need to restart the hostname service.
sudo /etc/init.d/hostname.sh stop
sudo /etc/init.d/hostname.sh start
Now, logout and log back in.