We are writing the same kind of topics since last week but all these are having different information.
If you want to see those article , navigate to the appropriate link from the below list
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 show 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
or
$ 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 daygeek-Y700
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 daygeek-Y700
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}' CentOS.2daygeek.com
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 127.0.1.1 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 daygeek-Y700
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 daygeek-Y700
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 HOSTNAME=CentOS.2daygeek.com