Ubuntu set hostname permanently (computer name) command

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:

  1. Open the terminal.
  2. Use the following command to open the /etc/hostname file in a text editor:
sudo nano /etc/hostname
  1. Enter the desired hostname in the file and save the changes by pressing Ctrl + O and then Ctrl + X.
  2. Open the /etc/hosts file:
sudo nano /etc/hosts
  1. Modify the file to include the following line, replacing new_hostname with your desired hostname:
127.0.0.1 localhost new_hostname
  1. Save the changes and close the file.
  2. 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.

Leave a Comment