How to Set or Change System Hostname in Linux

  • hostname, хостнейм, хост, host
  • 7

Newer version of different Linux distributions such as latest Ubuntu, Debian, CentOS, Fedora, RedHat, etc. comes with systemd, a system and service manager that provides a hostnamectl command to manage hostnames in Linux.

To set system hostname on SystemD based distributions, we will use hostnamectl command as shown:

hostnamectl set-hostname

For Older Linux distributions, which uses SysVinit in short init, can have their hostnames changed by simply editing the hostname file located in:

nano /etc/hostname

For example:

On RHEL/CentOS based systems that use init, the hostname is changed by modifying:

nano /etc/sysconfig/network

For example:

You can check the hostname using the next command:


Was this answer helpful?