Change your computer name in Ubuntu

Change your computer name in Ubuntu

There are times when we have to change our team name and we don't know where to do it. There may be many and varied reasons: a name that we choose at the time of installation that we do not like later, because it is going to be a work computer, because we have acquired another computer and the name of the current one is the one we want in our core team… For whatever reason, we want to tweak it.

Change PC name, also known as hostname, in Ubuntu or any of its variants is extremely simple: just edit the files hosts y hostname located in / etc /. This can be done with any text editor graphically or directly from the console with the help of GNU nano. Also, it is a process that may work on other Linux-based distributions.

Rename PC with GNU nano

The fastest is to do it using GNU nano. To change the name of the PC or hostname with this method, we first have to open the terminal and type the following:

sudo nano /etc/hosts

After entering our password, we will see a screen similar to this:

⁄etc⁄hosts

In my case, "ubuntu-box" is the name of the computer, specifically the one in which I test what reaches the latest Daily Build. Once the file is open, we navigate with the keyboard arrows to the name of the equipment and change it to the new one. When we're done, press Control+O and confirm that we want to save the file by pressing Enter. To exit the editor, press Control+X. Now we have to do the same with the file hostname, for which, in the same terminal, we write the following:

sudo nano /etc/hostname

In this file there is only the name of your team. You have to change it, putting the same one that we have put in /etc/hosts, and save and exit as we have done in the previous step.

⁄etc⁄hostname

Done, that's all we need to do. To see the changes, the last thing we have to do is restart the computer.

With a text editor like Gedit

Gnome TextEdit

Taking into account how easy it is from the terminal, I would leave it there, but I know that there are people who seem to be allergic to it and prefer to shoot whenever they can with something with Graphic interface. The problem with GUI programs is that there are so many of them, and each desktop or distribution uses its own. Ubuntu used Gedit until recently, and then switched to GNOME Text Editor, a GNOME editor that sits better on your desktop. Therefore, depending on when you read this article, everything will make more or less sense. It also doesn't seem to me that it makes much sense to want to escape the terminal when the first step for this would be to open the terminal, but hey. Everyone is comfortable with what they are comfortable with.

If we want to do it with a graphical interface, we have to know which text editor we are using. For example, if we want to use Gedit, we first have to install it, since, as we have explained, Ubuntu started to use GNOME Text Editor. Therefore, we will have to write the following:

sudo apt install gedit

Already with Gedit installed, the following command will be to open the file with this editor with super user permissions:

sudo gedit /etc/hosts

Once the editor is open, all we have to do is change the hostname as we have explained above, save and close the window. It must also be done with the file /etc/hostname.

If we are using another editor, we must change "gedit" by its name. For example, to do it with the GNOME editor you have to write sudo gnome-text-editor /etc/hostsBut there are times when it fails. If we are in a KDE environment, the editor is Kate, and launching it from the terminal doesn't work. What you have to do is open Dolphin, go to /etc/, open the hosts file, edit it, and when you save it, put the administrator password. NOTE: : This is valid at the time this article was written; it could stop being one if the developers of a desktop decide to make changes.

It's safe, but...

The process is a safe process, but there may be something that doesn't go quite right after some change. The best thing, without a doubt, is to choose the computer name correctly during the installation and not tweak anything in the future. When changing the hostname, there may be processes or programs that have remained with the previous profile, and it could stop working. Sometimes it's the same program that tells you there's a problem and fixes it, but there may be other cases where it's worth deleting a configuration folder.

If any program fails after the change, you can go to the file manager, press Ctrl+H to show the hidden files and look for the configuration files of the program that is not working at all. For example, the .mozilla folder if the Firefox browser failed or .config/BraveSoftware if Brave failed us. But, as I say, the problem is usually not serious.

More information - Shorten links from the consoleYakuake, the KDE dropdown console


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   George said

    Thanks! in another site I found that I only had to modify / etc / hosts and it gave me problems ... I did not know that / etc / hostname was necessary

  2.   nn said

    It was of no use, I did not understand

  3.   Hector Maciel said

    Thanks thanks friend for the tutorial I did not help graphically to change the name and it was too long, I wanted something smaller

  4.   Agustin said

    The new name appears, but the old one appears as an email account, what should I do?

  5.   liriccombene said

    the same thing happens to me 🙁