Ubuntu set hostname permanently (computer name) command

Ubuntu set hostname permanently (computer name) command

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:

  1. Open a terminal window on the Ubuntu system.

  2. Use the nano or vi text editor to edit the /etc/hostname file and set the hostname of the system. For example:

ref‮e‬r to:lautturi.com
sudo nano /etc/hostname
  1. In the /etc/hostname file, delete the current hostname and type the new hostname you want to set for the system. For example:
new-hostname
  1. Save the changes to the /etc/hostname file and exit the text editor.

  2. 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
  1. In the /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
  1. Save the changes to the /etc/hosts file and exit the text editor.

  2. 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.

Created Time:2017-10-30 14:27:28  Author:lautturi