Introduction
The Linux command hostnamectl is a command line utility used to manage the system hostname. It is used to set the system hostname, static hostname, pretty hostname, and transient hostname. It can also be used to query the system hostname, and to set the system’s NIS domain name. This command is available in most Linux distributions, including Ubuntu, Debian, Fedora, and CentOS.
Examples
The hostnamectl command is used to query and change the system hostname and related settings. It is part of the systemd system and service manager.
Syntax:
hostnamectl [OPTIONS…]
Options:
–static, –transient, –pretty, –pretty-transient, –no-ask-password
Examples:
1. To view the current hostname:
hostnamectl
2. To set a new hostname:
hostnamectl set-hostname newhostname
3. To set a static hostname:
hostnamectl set-hostname –static newhostname
Using the Hostnamectl Command in Linux
The hostnamectl command is a powerful tool in Linux that allows you to view and set the system hostname. It is a part of the systemd suite of tools and is used to manage system services, including the hostname. This command is available in most modern Linux distributions, including Ubuntu, Debian, CentOS, and Red Hat.
The hostnamectl command can be used to view the current hostname of the system, as well as set a new hostname. It can also be used to view and set the system’s DNS domain name, and to view and set the system’s NIS domain name. Additionally, it can be used to view and set the system’s static hostname.
To view the current hostname of the system, use the following command:
hostnamectl status
This will display the current hostname, as well as the system’s DNS domain name, NIS domain name, and static hostname. To set a new hostname, use the following command:
hostnamectl set-hostname new_hostname
This will set the system’s hostname to the new_hostname specified. To set the system’s DNS domain name, use the following command:
hostnamectl set-domainname new_domainname
This will set the system’s DNS domain name to the new_domainname specified. To set the system’s NIS domain name, use the following command:
hostnamectl set-nisdomainname new_nisdomainname
This will set the system’s NIS domain name to the new_nisdomainname specified. To set the system’s static hostname, use the following command:
hostnamectl set-static-hostname new_static_hostname
This will set the system’s static hostname to the new_static_hostname specified. The hostnamectl command is a powerful tool in Linux that allows you to view and set the system hostname, DNS domain name, NIS domain name, and static hostname.