Skip to content
Related Articles

Related Articles

How to Display and Set Hostname in Linux?
  • Last Updated : 18 Mar, 2021

Hostname is a unique name for a computer and computer network node in a network. It is also known as a Nodename, computer name or Sitename where it is a label that is assigned to a device that is connected to the computer network. Hostname has simple names consisting of words and phrases or they may be well-structured.


  • In the URL, the hostname is www.
  • Mail servers are often named after their function or protocol used and receive the corresponding hostname like mail, pop3, IMAP, etc.

Rules of Hostname

  • Host name will be a single word or phrase with no space.
  • A Hostname consists of only a combination of letters, numbers, periods, or hyphen.
  • Maximum length of the hostname will be 253 characters.
  • DNS(Domain Name Space) may be appended to the hostname.
  • The hostname cannot have an underscore.

How to display Hostname in Linux?

Step 1) Firstly open your terminal on Linux.

Step 2) Command ”Hostname” is used in order to display hostname in Linux operating system as shown below:


Also, without typing the command hostname you can identify your Linux hostname. 

In the above image see jagroop@jagroop-SVE1513CYNB so after @ you can identify your hostname which is:


How to display Domain Name?

Command “Domainname” is used to return the domain name of the Linux System. If your Linux device domain name is set then you will get “none” message as output. Else you will get your Domain name. In my Linux system, I don’t have any domain name so it will result in none as shown:

How to display hostname with more detailed information?

In order to display hostname with more detailed information we will use wither below command:


Or, In order to display hostname with more detailed information various types of commands are used, and these commands we will get by using command “hostname -h” which means that we want help regarding hostname. In the below output, all the commands applicable for hostname is shown as:

For example: I want to know the IP address of my hostname so, will choose the option -i which is implemented as:

How to set a hostname?

Step 1) Change the hostname using “hostnamectl”command using the syntax:

sudo hostnamectl set-hostname geeksforgeeks

When we run the above syntax, the system will ask password and execute it as shown:

Step 2) After step 1, restart your Linux system

Step 3) After restart, open the terminal.

Step 4) Now type command “hostname”, you will get your changed hostname output as:

My Personal Notes arrow_drop_up
Recommended Articles
Page :