Share!

Change the hostname of a Linux machine

The program to view and change a machine’s hostname in Linux is a program named hostname itself. In a machine’s with the hostname test, running the program will produce the following:

$ hostname
test

Temporary: Use hostname tool

To change the hostname, simply add the desired hostname as the argument, as the following example:

$ sudo hostname testmachine
$ hostname
testmachine

Permanent: Edit configuration file

The changes are however temporary, as the hostname will revert back to the original when the machine is rebooted. To make it permanent, just change the content of /etc/hostname to the desired hostname.