0 Comments

Do you need to change Ubuntu's hostname? Here are 3 ways you can quickly and easily change it. Both temporarily and permanently.

Have you ever found yourself staring at Ubuntu’s hostname and wondering why you even chose it in the first place? If you have, don’t go reinstalling Ubuntu just to change it. Take a look below as we list 3 different ways you can quickly and easily change it. Both temporarily and permanently.

How to change Ubuntu’s hostname temporarily

The quickest way to change Ubuntu’s hostname is with the temporary method. This will remain active until you reboot the machine.

  1. The first thing you need to do is fire up a terminal window. you can easily do this with Ctrl + Alt + T keys. Or alternatively, you can find the terminal in Ubuntu’s dash menu.

  2. With the terminal now open, enter the following command. Remember to change [NEW_HOSTNAME] to your desired hostname.

    sudo hostname [NEW_HOSTNAME]
    
  3. If successful, you will now see the new hostname displayed after the ‘@’ symbol in the terminal. If the name hasn’t changed you may need to restart the terminal. Alternatively, you can also type in the following command to double check:

    hostname
    

    Hostname - Ubuntu Hostname Temporary

How to change Ubuntu’s hostname permanently

There are two ways to permanently change the hostname in Ubuntu. You can either change it through the GUI or through the terminal. The simplest way is through the GUI, however, we’ve listed both methods below for you to choose.

  • Change Ubuntu’s hostname with the GUI

    1. To change the hostname with the GUI you will need to navigate to the settings. You can find it in Ubuntu’s dash menu by searching for “settings”. Or alternatively, you can find it in the system menu. It has a screwdriver and a spanner for its icon.

      Hostname - Settings Button

    2. In the settings scroll right down to the bottom to find the details menu and select it.

      Hostname - Ubuntu Settings Detail Menu

    3. Once inside the details menu, simply enter your new hostname in the textbox labeled Device name. When you’re happy with the changes hit Enter and restart your machine for the changes to take effect.

      Hostname - Ubuntu Settings

  • Change Ubuntu’s hostname with the terminal

    To change Ubuntu’s hostname with the terminal you will need to edit two files. /etc/hostname and /etc/hosts. The easiest way to do this is through the terminal.

    1. Fire up a new terminal window with the Ctrl + Alt + T hotkeys. Or open the terminal from the applications list in the dash menu.

    2. With the terminal open, you can now launch nano to edit these two files. Since they are system files you will also need to use elevated privileges with the use of sudo. First up we will edit the hostname file. To do this enter the following command into the terminal:

      sudo nano /etc/hostname
      
    3. In the hostname file, you will find your hostname on a single line. Go ahead and edit it to your desired new hostname. When you’re happy with the changes hit Ctrl + O to save the changes to the disk. Followed by the Ctrl + X keys to exit nano.

      Hostname - Hostname File Nano

    4. Next up edit the hosts file. Just like before you can edit the file with nano. Only this time change the file name to the hosts file like so:

      sudo nano /etc/hosts
      
    5. The hosts file contains a little more data but is still just as easy to edit. Taking a closer look you can find the hostname on the second line, just after an IP address. Head down to the second line and modify the hostname to your new name. Leaving the IP address intact. Once again, when your finished editing hit Ctrl + O to save the changes. And then Ctrl + X to exit.

      Hostname - Host File Nano

    6. With the two files now modified you can reboot the computer for the changes to take effect. You can either do this through the GUI menu or simply enter this command into the terminal:

      reboot
      

Amber Belle

Avid Ubuntu user with a soft spot for everything open source. I have been using Linux distributions my entire life, and I have been using Ubuntu since as far back as I can remember. My ideal setup

Comments