Linux “hostname” Command Examples
General Syntax of the “hostname” Command:
The general syntax of the “hostname” command in Linux is shown below:
Here, you can replace “parameter” with any flags or options used with the “hostname” command. Some of those flags or options are also described in the examples below. However, if you want to execute the simple “hostname” command, you can also do that without stating any parameter.
Examples of Linux “hostname” Command:
For learning the usage of the “hostname” command in Linux, you can go through the following examples:
Example # 1: Check the Hostname of your Linux System:
This command is most commonly used for checking the hostname of your Linux system by running it in the manner shown below:

Our Linux system’s hostname is shown in the following image:

Example # 2: Check the IP Address against the Hostname of your Linux System:
You can also check the IP address that is assigned to your Linux machine against its hostname by using the “hostname” command with the “-i” parameter as follows:

The IP address against the hostname of our Linux system is shown in the image below:

Example # 3: Check the Fully Qualified Domain Name of your Linux System:
If you want to check the fully qualified domain name of your Linux system, then you can use the “-f” flag with the “hostname” command as follows:

The fully qualified domain name of our Linux system is shown in the image below:

Example # 4: Check the Alias of the Hostname of your Linux System:
At times, users also set aliases against the hostnames of their systems. If you want to check the alias against the hostname of your system (if it exists), then you can use the “-a” parameter with the “hostname” command as follows:

Since we had not set up an alias for our system’s hostname, therefore, we were presented with a blank output, as shown in the image below:

Example # 5: Check the Short Hostname of your Linux System:
If there is a dot in your hostname, then the short hostname refers to the portion of your hostname before that dot. You can display the short hostname of your Linux system by using the “-s” flag with the “hostname” command as follows:

Since we did not have a dot in our system’s hostname, therefore, the short hostname of our Linux system is the same as our actual hostname, which is shown in the image below:

Example # 6: Change the Hostname of your Linux System:
If you want to change the hostname of your Linux system, then you can also do that while using the “hostname” command in the following manner:
Here, you will have to replace NewHostName with any desired new hostname you want to set up for your Linux system. This command will not show any output on the terminal upon successful execution.

You can confirm if a new hostname has been set up for your system or not by executing the command shown below:

From the output of the above-mentioned command, it is quite evident that our hostname has been changed successfully, as shown in the following image:

Conclusion:
We discussed the six different examples of using the “hostname” command in Linux in this article. To learn more about the usage of this command in Linux, you can run the “hostname –help” command in your system’s terminal.
About the author

Karim Buzdar
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.
How to Display and Set Hostname in Linux?
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.
Example:
- In the URL www.geeksforgeeks.org, 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 either 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:
Sorry, you have been blocked
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
What can I do to resolve this?
You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.
Cloudflare Ray ID: 803a770b58a898a9 • Your IP: Click to reveal 178.175.133.149 • Performance & security by Cloudflare
3 способа узнать имя хоста (компьютера) с помощью терминала Linux
Так же как адрес интернет-протокола или IP-адрес дает идентификацию вашему устройству, точно так же имя хоста является еще одним параметром, по которому можно узнать ваше устройство. Оно представляет собой строку символов, понятных человеку. В отличие от IP-адреса, имя хоста ПК легко запомнить и вспомнить. Для этого необходимо всегда знать имя хоста своего компьютера. В этой статье мы расскажем вам, как узнать имя хоста вашего ПК с помощью терминала Linux.
Поиск имени хоста компьютера в Linux
Чтобы найти имя хоста вашего ПК в Linux, вы можете выполнить любой из трех перечисленных ниже методов:
Метод № 1: Используйте команду hostname
Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав enter. Открывшееся окно терминала показано ниже:

Теперь введите в терминале команду hostname и нажмите клавишу Enter.

Как только вы нажмете клавишу Enter, имя хоста вашего компьютера появится в терминале. Это показано на рисунке ниже:
Имя хоста, отображаемое в оболочке системы Linux
Способ № 2: Используйте команду hostnamectl
Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав enter.
Теперь введите команду:
в терминале и нажмите Enter.

Как только вы нажмете клавишу Enter, в окне терминала появится имя хоста вашего компьютера. Это показано ниже:
Отображается подробная информация о системе Linux, включая имя хоста.
Способ № 3: Используйте команду cat
Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав Enter.
Теперь введите команду:
в терминале и нажмите клавишу Enter.

Как только вы нажмете клавишу Enter, на терминале отобразится имя хоста вашего компьютера.
Заключение
Перечисленные выше три метода действительно очень просты и легки. Теперь вы можете найти имя хоста вашего компьютера за несколько секунд и без каких-либо проблем. Надеюсь, эти методы помогут вам.