Linux: Changing Hostname on a Linux Server.

Changing Hostname On a Linux Server.
April 30, 2019.

The manual method:
This method will work on nearly any Linux distribution.

Before we get into this method, do note it will require you to reboot the server. Otherwise, the new hostname will not go into effect and you could wind up with some random issues—depending upon what your server is used for.

Open up a terminal window. We can find out what our current hostname is by issuing the command hostname in Linux.

[test@testdb]#hostname
#testdb.dept118.local
[test@testdb]#


To modify the hostname, we need to modify two files.
vi /etc/hostname.
In this file you will see a single line that contains your system hostname. Edit that line to reflect the new hostname. Once you’ve done that, save and close the file.

Now we modify /etc/hosts file.
vi /etc/hosts
In this file, you’ll want to change any instance of the old hostname to reflect the new hostname. There should only be one entry/line to change.

Save the file.
Exit.
Reboot.

Once it is up, the new hostname should take effect. Open a terminal window. Issue hostname command. You will see the new name within the prompt.

Notes on VM Linux node existing within a windows infrastructure.
When we change the hosts file and the hostname above, the DNS entries local to the Linux VM node will change to the new name, BUT, if we are connecting to this from a Windows system, say, a remote putty session or any other remote session connect, then the DNS entries within the Windows domain need to be changed to point at at the new hostname.

Prakash