How to view the host name in linux

02-04-2023

Most people do not understand the knowledge points of this article on how to check the hostname in Linux, so the editor summarizes the following content for you. The content is detailed, the steps are clear, and it has certain reference value. I hope you can finish reading this article. The article can gain something, let's take a look at this article on how to view the host name in Linux.


How to view the host name in linux: 1. View the system host name through the hostnamectl command; 2. Use hostname to view the host name; 3. Use uname to view the host name; 4. Use nmcli to view the host name; 5. Use sysctl to view the host name; 6. Use cat /etc/hostname to view the host name; 7. Use cat /etc/hosts to view the host name; 8. Use ProcFS to view the host name; 9. Use nmtui to view the hostname.

10 Ways to View Hostname in Linux

The hostname (also known as the computer name) is provided to connect to the network The name of a device (could be a system, switch, router, etc.) used to identify it across the network. You cannot have two systems with the same hostname on the same network. The purpose of the Linux system to name the current host is to make it easier to remember, especially when deploying a cluster. Generally, the host name will be associated with the IP address, so that in other clusters, the host does not need to be modified accordingly if the IP is changed to other cluster machines.

By default, the hostname can be found in the terminal, but the first part is only shown if the hostname is relatively large (every hostname usually has at least one network address associated with it). Let's take a look at the 10 ways to view the host name of Linux.

1, View the hostname using hostnamectl

hostnamectl can be used to query and change the system hostname and related settings. Run the hostnamectl command to view the system hostname as follows:

[root@localhost sharplee]# hostnamectl
or
[root@localhost sharplee]# hostnamectl status

1.jpg

From the figure above, we can see that the current host name is localhost.localdomain.

2, View the hostname using hostname

The hostname is used to set or display the current host, domain or node name of the system. Many network programs use these names to identify computers. NIS/YPAlso use this domain name, the command is as follows:

[root@localhost sharplee]#hostname


3, check the host name using uname

uname (meaning unix name) is a utility command which prints system information such as name, version and other details about the system, and the operating system running on it. The command is as follows:

[root@localhost sharplee]# uname -a | awk '{print $2}'

2.jpg

4, check the host name using nmcli< /p>

nmcli command is mainly used for network management control and network status report. nmcli is mainly used to create, display, edit, delete, activate and deactivate network connections, and control and display the status of network devices. The command is as follows:

[root@localhost sharplee]# nmcli general hostname


5, use sysctl

sysctl command to view the host name It is mainly used to modify kernel parameters when Linux is running. The available parameters are the parameters listed under /proc/sys/. Procfs is required for sysctl support in Linux. You can use sysctl to read and write sysctl data. The view hostname command is as follows.

[root@localhost sharplee]# sysctl kernel.hostname


You can view the host name through the above five commands, and then look at it Look at the last five, but in general, the first five are enough.

6. Check the hostname using cat /etc/hostname

Check the hostname by looking at the /etc/hostname file. The commands are as follows.

[root@localhost sharplee]# cat /etc/hostname


7, to view the host name use cat /etc/hosts

Check the hostname by looking in the /etc/hosts file. /etc/hosts is mainly used to configure the dns mapping relationship of the machine, generally the host name of the ip address, used for the mapping relationship between ip and the host. The commands are as follows.

[root@localhost sharplee]# cat /etc/hosts | grep 127.0.0.1


8, view the hostname through ProcFS

The proc file system (procfs) is a special file system in Unix-like operating systems that provides information about processes and other system information . It is sometimes called the process information pseudo-filesystem. It does not contain "real" files, but runtime system information (such as system memory, mounted devices, hardware configuration, etc.).

[root@localhost sharplee]# cat /proc/sys/kernel/hostname


9, use nmtui to view the hostname

nmtui nmtui is a graphical based application for interacting with NetworkManager. When starting nmtui, the system will prompt the user to select the activity to be performed. Unless you choose to exit, otherwise, press Enter to select the default parameters, which can be modified after entering.

[root@localhost sharplee]#nmtui


10, check the host name through /etc/sysconfig/network

"/ etc/sysconfig/network" file specifies other information valid for all network interfaces on the system, this command can only be used on RHEL/CentOS 6 systems. Systems above Centos6 cannot be used.

[root@localhost sharplee]#$ cat /etc/sysconfig/network | grep -i hostname
HOSTNAME=localhost.localdomain

pass the above 10 It can be seen from the above methods that there are many ways to view the Linux host name, but the editor here recommends that you use the first five ways to pass commands, which cover almost any system type in Linux.


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us