On Debian, the hostname is set at startup thanks to the script /etc/init.d/hostname.sh which uses the file /etc/hostname. We can use this file to update the computer hostname and its FQDN (fully qualified domain name).

Caution: in the /etc/hosts file, the hostname and FQDN order must be respected.

~$ echo "my-computer" > /etc/hostname
~$ echo "127.0.0.1 my-computer.my-domain.ext my-computer localhost" > /etc/hosts
~$ /etc/init.d/hostname.sh

You can check the change with the following lines:

~$ hostname
my-computer
~$ hostname --fqdn
my-computer.my-domain.ext

The old hostname may still be present in the command line prompt. Just logoff then login to make it dissapear Wink.

Comments   

# Really usefuldonjuanique 2011-11-13 21:01
After seeking and testing several ways of doing this, at last I found an easy way to do it.
Thank you.
Reply
# emptying the rest of your /etc/hostsSteven 2012-05-09 10:44
by using > to fill the /etc/hosts file you\'ll empty the rest of your hosts file. You might want to use the >> operator so it\'s added instead of emptying the whole file, you might want to check what is in it before you overwrite it out of the blue.
Reply