In order to display a computer name in CentOS 7/8 and RHEL 7/8 systems via console, issue the following command. The -s
flag displayed the computer short name (hostname only) and the -f
flag displays the computer FQDN in the network (only if the computer is a part of a domain or realm and the FQDN is set).
You can also display a Linux system hostname by inspecting the content of /etc/hostname file using the cat command.
In order to change or set a CentOS 7/8 machine hostname, use the hostnamectl command as shown in the below command excerpt.
In addition to hostname command, you can also use hostnamectl command to display a Linux machine hostname.
In order to apply the new hostname, a system reboot is required, issue one of the below commands in order to reboot a CentOS 7 machine.
A second method to set up a CentOS 7/8 machine hostname is to manually edit the /etc/hostname file and type your new hostname. Also, a system reboot is necessary in order to apply the new machine name.
A third method that can be used to change a CentOS 7/8 machine hostname is by using the Linux sysctl interface. However, using this method to change machine name results in setting-up the machine transient hostname.
The transient hostname is a special hostname initialized and maintained only by the Linux kernel as an auxiliary machine name in addition to he static hostname and doesn’t survive reboots.
To display machine transient hostname issue the below commands.
Finally, the hostnamectl command can be used to achieve the following hostname setups: –pretty, –static, and –transient.
Although there are other more specific ways to change a Linux machine hostname, such as issuing nmtui command or manually editing some configuration files specific to each Linux distribution (/etc/sysconfig/network-scripts/ifcfg-ethX for CentOS), the above rules are generally available regardless of the used Linux distribution.
sumber : https://www.tecmint.com/set-change-hostname-in-centos-7/
No comments: