How do you set the hostname in Linux?

To set the hostname on a Linux system, you can follow these steps:

  1. Open the terminal window and enter the following command to check the current hostname:
hostname
  1. To permanently set the hostname, replace “newhostname” with the desired hostname in the following command.
sudo hostnamectl set-hostname newhostname
  1. Use the following command to check if the modified hostname has been successfully saved:
hostname
  1. To take effect immediately, you can restart the network service.
sudo systemctl restart NetworkManager

After completing the above steps, the hostname of your Linux system has been successfully set.

bannerAds