. . .

How To Change The Hostname in Centos 7.

Step 1: Open a terminal window. You can do this by pressing 'Ctrl + Alt + T' or by accessing the terminal from the Applications menu.

Step 2: To check the current hostname, you can use the following command:-
# [ hostname ]

Step 3: To change the hostname temporarily (until the next reboot), you can use the 'hostname' command with the new hostname. For example:-
# [ sudo hostname your-new-hostname ]
Note: Replace “your-new-hostname” with the desired hostname.

Step 4: To make the hostname change permanent, you need to update the '/etc/hostname' file with the new hostname. Use a text editor to open the file. You can use a command-line editor like nano or vi. Here’s an example using 'nano':-
# [ sudo nano /etc/hostname ]
Note: Replace the existing hostname with your new hostname and save the file.

Step 5: Additionally, you need to update the '/etc/hosts' file with the new hostname. Open the file using a text editor:-
# [ sudo nano /etc/hosts ]
Find the line with the old hostname and update it with the new one and Save the file.

Step 6: After making these changes, you should restart the system or restart the 'systemd-hostnamed' service for the changes to take effect:-
# [ sudo systemctl restart systemd-hostnamed ]

Step 7: Alternatively, you can reboot the system:-
# [ sudo reboot ]
After the reboot, your CentOS 7 system should have the new hostname. You can verify this by running the 'hostname' command again.