Hostname is the label of a system or in other words it is a human readable name of a system, after setting up the hostname of the device then it becomes easy to manage and access based on their label or hostname.
In this post, we will learn how to set or change the hostname of a linux system using hostnamectl and nmtui tool. Hostname can be of three types,
- Pretty – It supports all kind of special characters.
- Static – It is the type of hostname which used to initialize the kernel hostname at boot
- Transient – It is the hostname which is set base on based network configuration.
In static and transient hostname, only accepted characters of internet domain name is allowed to use whereas there is no limit on characters in pretty hostname.
Set hostname with hostnamectl command
In modern linux distributions like RHEL, CentOS, Rocky Linux, Debian and Ubuntu hostnamectl is available for setting up the hostname. When we run hostnamectl command without any arguments then it will display the current hostname,
Alternate way to check the hostname of your system is by running hostname command without any options, example is show below
[email protected]:~$ hostname ubuntu [email protected]:~$
Set Static Hostname
To set the static hostname, run the following hostnamectl command,
$ sudo hostnamectl set-hostname <hostname>
$ sudo hostnamectl set-hostname "linuxbuzz.local.lan" $ exec bash
Verify the hostname using following commands,
$ hostname $ hostnamectl
Output of above command:
Set Pretty Hostname
To set the pretty type hostname then use –pretty arguments in hostnamectl command, example is shown is below:
$ sudo hostnamectl --pretty set-hostname "PKUMAR_LinuxBuzz ##Blog##" $ exec bash $ hostnamectl
Perfect, above shows that static and pretty hostname are set.
To remove the static hostname, run
$ sudo hostnamectl set-hostname ""
To remove pretty hostname, run
$ sudo hostnamectl --pretty set-hostname ""
Set hostname using nmtui tool
Static hostname can also be set using nmtui tool. It’s simple and straight forward, start nmtui tool by running,
Choose ‘Set system hostname’ option and hit enter. In the following window, specify the hostname that you want to set and then choose OK and hit enter.
Choose OK in the following window and then quit the nmtui tool.
Verify the new hostname by running following command
[email protected]:~$ hostname linuxbuzz.example.lan [email protected]:~$
Great, that’s all from this post. I hope you have found it informative and insightful. Please do share your feedback and queries in below comments section.
Read Also: How to Setup Chroot SFTP Server in Linux