10 Methods To Check The HostName In Linux

We are writing the same kind of topics since last week but all these are having different information. If you want to see those, navigate to the appropriate link and those are How To Change HostName In Linux and 4 Methods To Change The HostName In Linux.

This command is must when you are working in a server through the JUMP server. If you want to reboot a server, this command will help you to check whether you are in the right server or not.

If you don’t know which server you are working then you may wrongly reboot the different server or JUMP server instead of actual server.

You may ask, by default we can able to see the hostname information in the terminal then why we need to check the hostname once again using following command?

The default terminal won’t shows the full hostname, which make you to do the mistake so, i would suggest you to check using one of the below command on this.

Also, if you want to avoid such a thing permanently you can install the molly-guard utility that helps you to avoid Accidental Shutdown Or Reboot in Linux.

It can be done in the following 10 methods.

    • hostnamectl Command: hostnamectl command is controling the system hostname.
    • nmcli Command: nmcli is a command-line tool for controlling NetworkManager.
    • nmtui Command: nmtui is a text User Interface for controlling NetworkManager.
    • /etc/hostname file: This file is containing the static system hostname.
    • uname Command: Print certain system information.
    • hostname: Show or set system host name.
    • /etc/hosts: /etc/hosts file is an operating system file that maps hostnames to IP addresses.
    • sysctl: sysctl command allows us to configure kernel parameters at runtime.
    • /etc/sysconfig/network: The /etc/sysconfig/network file specifies additional information that is valid to all network interfaces on the system.
    • /proc/sys/kernel/hostname: The proc filesystem (procfs) is a special filesystem in Unix-like operating systems.

Method-1: Check The HostName Using hostnamectl Command in Linux

hostnamectl may be used to query and change the system hostname and related settings.

Simple run the hostnamectl command to view the system hostname.

$ hostnamectl
$ hostnamectl status

   Static hostname: daygeek-Y700
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 31bdeb7b83230a2025d43547368d75bc
           Boot ID: 267f264c448f000ea5aed47263c6de7f
  Operating System: Manjaro Linux
            Kernel: Linux 4.19.20-1-MANJARO
      Architecture: x86-64

Method-2: Check The HostName Using hostname Command in Linux

Hostname is the program that is used to either set or display the current host, domain or node name of the system. These names are used by many of the networking programs to identify the machine. The domain name is also used by NIS/YP.

$ hostname

Method-3: Check The HostName Using /etc/hostname File in Linux

Alternatively, we can view the hostname by using the /etc/hostname file.

Check the current hostname using /etc/hostname file.

$ cat /etc/hostname

Method-4: Check The HostName Using uname Command in Linux

uname (stands for unix name) is an utility that prints the system information like name, version and other details about the system and the operating system running on it.

$ uname -a | awk '{print $2}'

Method-5 : Check The HostName Using /etc/hosts File in Linux

is an operating system file that maps hostnames to IP addresses before DNS can be referenced. It is a plain text file, one line per IP address. It’s a static table lookup for hostnames.

$ cat /etc/hosts | grep daygeek	daygeek-Y700

Method-6: Check The HostName Using nmcli Command in Linux

nmcli is a command-line tool for controlling NetworkManager and reporting network status.

nmcli is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status. Also, it allow us to view the hostname.

Use the following format to view the current hostname using nmcli.

$ nmcli general hostname

Method-7: Check The HostName Using sysctl Command in Linux

sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl support in Linux. You can use sysctl to both read and write sysctl data.

$ sysctl kernel.hostname
kernel.hostname = daygeek-Y700

Method-8: Check The HostName Using ProcFS in Linux

The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information.

It’s sometimes referred to as a process information pseudo-file system. It doesn’t contain ‘real’ files but runtime system information (e.g. system memory, devices mounted, hardware configuration, etc).

$ cat /proc/sys/kernel/hostname

Method-9: View The HostName Using nmtui Command in Linux

nmtui is a curses‐based TUI application for interacting with NetworkManager. When starting nmtui, the user is prompted to choose the activity to perform unless it was specified as the first argument.

Run the following command on terminal to launch the terminal user interface.

$ nmtui

Method-10: Check The HostName Using /etc/sysconfig/network File in Linux

The /etc/sysconfig/network file specifies additional information that is valid to all network interfaces on the system.

For RHEL 6/CentOS /OEL 6 Systems only:

$ cat /etc/sysconfig/network | grep -i hostname

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

Please support the site
By clicking any of these buttons you help our site to get better