To set the hostname (computer name) of an Ubuntu Linux system permanently, you can edit the /etc/hostname
file and the /etc/hosts
file. The /etc/hostname
file contains the hostname of the system, and the /etc/hosts
file contains the mapping of hostnames to IP addresses.
To set the hostname of an Ubuntu Linux system permanently, follow these steps:
Open a terminal window on the Ubuntu system.
Use the nano
or vi
text editor to edit the /etc/hostname
file and set the hostname of the system. For example:
sudo nano /etc/hostname
/etc/hostname
file, delete the current hostname and type the new hostname you want to set for the system. For example:new-hostname
Save the changes to the /etc/hostname
file and exit the text editor.
Use the nano
or vi
text editor to edit the /etc/hosts
file and set the hostname of the system. For example:
sudo nano /etc/hosts
/etc/hosts
file, find the line that starts with 127.0.1.1
and replace the hostname on that line with the new hostname you want to set for the system. For example:127.0.1.1 new-hostname
Save the changes to the /etc/hosts
file and exit the text editor.
Restart the networking service to apply the changes. You can use the systemctl
command with the restart
option and the network
unit to restart the networking service. For example:
sudo systemctl restart network
After following these steps, the hostname of the Ubuntu Linux system will be set to the new hostname you specified in the /etc/hostname
and /etc/hosts
files. The changes will be permanent and will survive a reboot of the system.
Keep in mind that you must have the necessary permissions to edit the /etc/hostname
and /etc/hosts
files on your system. If you do not have the necessary permissions, the text editor will display an error message.
For more information on how to set the hostname of an Ubuntu Linux system, you can refer to the Ubuntu documentation.