How do you set the hostname in Linux?
To set the hostname on a Linux system, you can follow these steps:
- Open the terminal window and enter the following command to check the current hostname:
hostname
- To permanently set the hostname, replace “newhostname” with the desired hostname in the following command.
sudo hostnamectl set-hostname newhostname
- Use the following command to check if the modified hostname has been successfully saved:
hostname
- 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.