To set the hostname (computer name) of an Ubuntu system permanently, you need to modify two files: /etc/hostname
and /etc/hosts
.
Here’s how to set the hostname in Ubuntu:
- Open the terminal.
- Use the following command to open the
/etc/hostname
file in a text editor:
sudo nano /etc/hostname
- Enter the desired hostname in the file and save the changes by pressing
Ctrl
+O
and thenCtrl
+X
. - Open the
/etc/hosts
file:
sudo nano /etc/hosts
- Modify the file to include the following line, replacing
new_hostname
with your desired hostname:
127.0.0.1 localhost new_hostname
- Save the changes and close the file.
- Finally, use the following command to reboot the system for the changes to take effect:
sudo reboot
Once the system has restarted, you can verify the hostname has been set permanently by using the hostname
command.