To set the hostname in Red Hat / CentOS 5:
vi /etc/sysconfig/network #change it here vi /etc/hosts #and here echo server1.example.com > /etc/hostname #and here hostname server1.example.com #and here for good measure /sbin/service network restart #restart the network
for Ubuntu you just need
echo server1.example.com > /etc/hostname #here vi /etc/hosts #and here
rm /etc/ssh/ssh_host_* dpkg-reconfigure openssh-server