Method One:
1.Open a terminal or SSH into the Linux system.
- hostname
4.Use the following command to change the hostname:
- hostnamectl set-hostname <new_hostname>
Replace new-hostname with the desired hostname you want to set.
5.Reboot the system for the changes to take effect, or you can run the following command to apply the new hostname without rebooting:
- systemctl restart systemd-hostnamed
6.To verify if the hostname has been successfully changed, use the following command:
- hostname
If the output matches the new hostname you set, it indicates that the hostname has been successfully changed. After rebooting the system, verify that the modification has taken effect.
Method 2:
1.Open the "/etc/hostname" file using the following command:
- vi /etc/hostname
2.To change the hostname to your desired name in the opened file
To start editing, press "a" and delete the previous hostname. Set your new hostname. After making the changes, press "Esc" to exit edit mode. Then, press Shift+":" and type "wq" to save and exit.
3.After restarting the Linux system, check whether the hostname has taken effect.