How to change the machine name in Linux from the terminal

Change the machine name in Linux Any user who has installed Linux on their computer will have seen the step in which we choose our username, password and computer name. By default, many Linux distributions name the machine "Username" - "PC-Model", which can be translated as "pablinux-Aspire-One-MODEL". Personally, I have never liked that name and in this step I change it to another. If, for whatever reason, we want change team name After the operating system is installed, most Linux distributions do not have any options available in the settings.

As almost always with almost everything in Linux, we can do this by middle of terminal. Unlike other changes such as the Username, change the team name, which is also known as hostname, it is something simple and totally safe. You will only have to make two changes divided into several steps that we explain below.

Changing the team name is completely safe

  1. The first thing we will do is open the terminal, something we can do with the shortcut Ctrl + Alt + T in many Linux distributions.
  2. We introduce the following command, where we will have to change "newname" by the name we want to use:
sudo hostname nuevonombre
  1. Next, we write the following and enter the password of our user:
sudo nano /etc/hosts
  1. The above will open the editor of our hosts. There we have to change the name of our team and put the new one. We can move through the editor with the scroll keys of our PC.
  2. Once changed, we press Ctrl + O to save and Enter to confirm the changes.
  3. Finally, we exit with Ctrl + X.

At no point in the process will we see any changes. To see it, the best we can do restart terminal, at which time we will see the name of our user, the at sign and the new name of the team. I used to use the same name as the user, but it never convinced me. Now I have opted to put the version of the operating system that I am using, in this case K (ubuntu) 1904. It is important to mention that if we put the point, it will only accept the first part, which in this example would be "19".

With nmcli

If the above method does not work for us, we can also use the command nmcli. With the following command we will see the general name of the equipment:

nmcli general hostname

To change the name of the team, we will add a new name to the previous command, which in my example would look like this:

nmcli general hostname K1904

Was this little tutorial on how to change the machine name in Linux helpful to you?


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

6 comments, leave yours

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  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.   Luis said

    as it is rarely seen: concrete, practical and above all: it works.

  2.   Julian said

    This tutorial is the best, not only did it teach me how to change the host name, but also how to write plain texts, through the nano command, thank you very much.

  3.   riverbank said

    Hello, provide with:

    sudo hostname newname
    sudo nano / etc / hosts

    This changed the name that appears after the @ in the terminal, but the team name remained unchanged. Also, after a pc restart, the terminal would revert to the same name.

    Then I tried with

    nmcli general hostname hostname

    and this did work for me.
    Thank you very much.

  4.   Ur said

    Yes Yes ! ! !

    Funca!

  5.   Juan said

    The second option worked for me
    Thank you

  6.   Luis Mitz said

    The first method did not work for me, but the second method with nmcli if it worked for me currently I use KDE neon and in case someone wants to know how to do it in that distro, use the second