Skip to content

What is hostname Linux command?

The Linux hostname command is used to view or set the system’s hostname. It can be helpful for identifying the system within a network or modifying the hostname temporarily or permanently.

Terminal window
hostname [option]
OptionDescription
-aDisplay the alias name
-dDisplay the DNS domain name
-fDisplay the FQDN (fully qualified domain name)
-iDisplay the network address (IP address)
-sDisplay the short hostname

There are no specific parameters for the hostname command.

Terminal window
hostname

This command will display the current hostname of the system.

Display the FQDN (Fully Qualified Domain Name)

Section titled “Display the FQDN (Fully Qualified Domain Name)”
Terminal window
hostname -f

Use this command to display the fully qualified domain name (FQDN) of the system.

Terminal window
sudo hostnamectl set-hostname newhostname

This command allows changing the hostname to a new one, in this case, “newhostname”.

Terminal window
hostname -s

The -s flag is used to display the local hostname of the system.

Display all information about the hostname

Section titled “Display all information about the hostname”
Terminal window
hostname -a

By using the -a flag, you can display all information associated with the hostname of the system.

To use the hostname command in bash, execute the following command:

Terminal window
hostname

To set a new hostname in Linux using the hostname command, follow this example:

Terminal window
hostname newhostname

How to display the FQDN using hostname in Linux?

Section titled “How to display the FQDN using hostname in Linux?”

To display the Fully Qualified Domain Name (FQDN) using the hostname command in Linux, use the following command:

Terminal window
hostname --fqdn

How to display the domain name using hostname in Linux?

Section titled “How to display the domain name using hostname in Linux?”

To display the domain name using the hostname command in Linux, you can run:

Terminal window
hostname --domain

How to display the short hostname using hostname in Linux?

Section titled “How to display the short hostname using hostname in Linux?”

To display the short hostname using the hostname command in Linux, you can use:

Terminal window
hostname --short

How to display the IP address associated with the hostname using hostname in Linux?

Section titled “How to display the IP address associated with the hostname using hostname in Linux?”

To display the IP address associated with the hostname using the hostname command in Linux, execute the following:

Terminal window
hostname -I

How to display all the information available with hostname in Linux?

Section titled “How to display all the information available with hostname in Linux?”

To display all the information available with the hostname command in Linux, you can run:

Terminal window
hostname --all-fqdn

How to display the version information for hostname in Linux?

Section titled “How to display the version information for hostname in Linux?”

To display the version information for the hostname command in Linux, use the following command:

Terminal window
hostname --version
  • Display or set the system’s hostname
  • Show the DNS domain name of the system
  • Print the FQDN (Fully Qualified Domain Name) of the system
  • Retrieve or change the NIS (Network Information Service) domain name
  • Return the local host name
  • Specify the version and release information of the operating system