In this Post we will discuss how to change hostname in centos 7 and Red-Hat 7.

Hostname
A computer hostname represents a unique name that gets assigned to a computer in a network in order to uniquely identify that computer in that specific network. Follow the below steps for change hostname in centos 7
you should keep in mind the following rules:
- hostnames can contain letters (from a to z).
- hostnames can contain digits (from 0 to 9).
- hostnames can contain only the hyphen character ( – ) as a special character.
- hostnames can contain the dot special character ( . )
- hostnames can contain a combination of all three rules but must start and end with a letter or a number.
- hostnames letters are case-insensitive.
Method 1
Set a CentOS 7/8 machine hostname, after change hostname in centos 7 use the hostnamectl command as shown in the below command excerpt.
syntax
- #hostnamectl set-hostname your-new-hostname
example
- #hostnamectl set-hostname mytest_vm
Note: Now In order to apply the new hostname, system reboot is required, issue one of the below commands in order to reboot.
- # init 6
- # systemctl reboot
- # shutdown -r
Now display the hostname issue one of the below command.
- # hostname
- # hostname -s
- # hostname -f
- # cat /etc/hostname
The -s flag displayed the computer short name (hostname only) and the -f flag displays the computer FQDN.
If you want to see addition information about hostname, you can also use hostnamectl command to display a Linux machine hostname.
- # hostnamectl
Method 2
second method to set up hostname is to manually edit the /etc/hostname file and type your new hostname and save the file. Also, a system reboot is necessary in order to apply the new machine name.
- # vi /etc/hostname
Leave your message if anything missed and we appreciate your comments. You can also watch this video “How to change hostname in centos 7“.