Here is an example of changing the hostname in Linux.
First, switch to the root user or add “sudo” before the commands.
Let’s see the current hostname:
hostname
uname -n
sysctl kernel.hostname
Let’s see what hostname is specified in the configuration file:
cat /etc/hostname
cat /etc/hosts
To change the hostname, use the command, it changes it in /etc/hostname, as well as other places:
hostnamectl set-hostname IXNFO
If necessary, add a new hostname here:
nano /etc/hosts
In order for the new hostname to take effect, you can reboot the server or change it immediately:
hostname NEW_HOSTNAME
Or so:
sysctl kernel.hostname=NEW_HOSTNAME
Both previous commands set the hostname before the system is restarted, and after the startup the system takes the hostname from the file /etc/hostname.