Change Hostname Permanently on Debian or Ubuntu

Change Hostname Permanently on Debian or Ubuntu

On Ubuntu and Debian

We can edit the file /etc/hostname and change the hostname and then run:

/etc/init.d/hostname.sh start

Steps:

1. sudo gedit /etc/hostname and edit the /etc/hosts file also.
2. Save the file with the hostname you like to set
3. sudo /etc/init.d/hostname.sh start

Debian based systems use the file /etc/hostname to read the hostname of the computer at boot time and set it up using the init script /etc/init.d/hostname.sh

If you get errors - hostname: the specified hostname is invalid  the check and find out if there is any edit error in the above files.