Ubuntu 22.04 change hostname

The purpose of this tutorial is to show how to change the system hostname on Ubuntu 22.04 Jammy Jellyfish Linux. This can be done via command line or GUI, and will not require a reboot in order to take effect.

The hostname of a Linux system is important because it is used to identify the device on a network. The hostname is also shown in other prominent places, such as in the terminal prompt. This gives you a constant reminder of which system you are working with.

Hostnames give us a way to know which device we are interacting with either on the network or physically, without remembering a bunch of IP addresses that are subject to change. You should pick a descriptive hostname like “ubuntu-desktop” or “backup-server” rather than something ambiguous like “server2.”

Read on to see how to change hostname on Ubuntu 22.04.

In this tutorial you will learn:

  • How to change the hostname on Ubuntu 22.04 via command line
  • How to change the hostname on Ubuntu 22.04 via GNOME GUI
Ubuntu 22.04 change hostname
Ubuntu 22.04 change hostname
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 22.04 Jammy Jellyfish
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Ubuntu 22.04 change hostname via command line




Changing the hostname on Ubuntu 22.04 is a rather simple process involving just few steps.

  1. First, check your current hostname. To do so use either hostnamectl or hostname command:
    $ hostname
    ubuntu
    

    Your output of the hostnamectl command may look similar to the one below:

    $ hostnamectl
     Static hostname: ubuntu
           Icon name: computer-vm
             Chassis: vm
          Machine ID: 4c1c3db5471746bd814d2bf4344b59eb
             Boot ID: c6606d2c45ea4caba20b0f154f68ee64
      Virtualization: oracle
    Operating System: Ubuntu Jammy Jellyfish
              Kernel: Linux 5.13.0-19-generic
        Architecture: x86-64
     Hardware Vendor: innotek GmbH
      Hardware Model: VirtualBox
    

    In either case the current hostname of our system is ubuntu.

  2. Next, use the hostnamectl command to change the hostname of your Ubuntu 22.04 system. For an example, we will switch our hostname to linuxconfig.
    $ sudo hostnamectl set-hostname linuxconfig
    

    The above command will change the hostname of our Ubuntu 22.04 system to linuxconfig.

    NOTE
    Upon changing your hostname using the hostnamectl command no system reboot is required to apply the hostname change.
  3. Next, edit the /etc/hosts file to reflect the change by executing the command sudoedit /etc/hosts. For example, change:

    FROM:

    127.0.0.1 localhost
    127.0.1.1 ubuntu
    

    TO:

    127.0.0.1 localhost
    127.0.1.1 linuxconfig
    
  4. Execute the hostnamectl command to confirm the hostname change:
    $ hostnamectl
     Static hostname: linuxconfig
           Icon name: computer-vm
             Chassis: vm
          Machine ID: 4c1c3db5471746bd814d2bf4344b59eb
             Boot ID: c6606d2c45ea4caba20b0f154f68ee64
      Virtualization: oracle
    Operating System: Ubuntu Jammy Jellyfish
              Kernel: Linux 5.13.0-19-generic
        Architecture: x86-64
     Hardware Vendor: innotek GmbH
      Hardware Model: VirtualBox
    

Ubuntu 22.04 change hostname via GNOME GUI




The instructions for changing the hostname on Ubuntu 22.04 from a graphical user environment are going to vary depending on the desktop environment you are using. The default desktop environment for Ubuntu 22.04 is GNOME, so we will be covering the instructions for that one below. If you have a different desktop environment, you may need a slightly different set of instructions.

  1. Start by clicking on the upper right area of your desktop, in order to bring up the Settings option. Then, open up the Settings panel.
    Open Settings in GNOME on Ubuntu 22.04
    Open Settings in GNOME on Ubuntu 22.04
  2. On the left side of the panel, scroll all the way down to the About tab. You will see your device name listed on the right side of the Settings screen.
    Viewing hostname on Ubuntu 22.04 from GNOME settings panel
    Viewing hostname on Ubuntu 22.04 from GNOME settings panel
  3. Next, click on the hostname. A new window will pop up, where you can type the desired hostname you would like to use. As an example, we are changing the hostname to linuxconfig in the screenshot below.
    Changing the hostname on Ubuntu 22.04 via GNOME GUI
    Changing the hostname on Ubuntu 22.04 via GNOME GUI
  4. When you are satisfied with the changes, click the green Rename button to finalize it. When done, you can close the Settings menu completely. If you would like to verify the change, you can open a terminal and type the hostname command.
    $ hostname
    linuxconfig
    

Closing Thoughts

In this tutorial, we saw two methods for changing the hostname on Ubuntu 22.04 Jammy Jellyfish via command line and GUI. We also learned about the importance of picking an applicable hostname to assist in the easy identification of a system. Administrators can use these methods to ensure that they have a network of appropriately named devices.