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
|Category||Requirements, Conventions or Software Version Used|
|System||Ubuntu 22.04 Jammy Jellyfish|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – 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.
- First, check your current hostname. To do so use either
$ hostname ubuntu
Your output of the
hostnamectlcommand 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
- Next, use the
hostnamectlcommand to change the hostname of your Ubuntu 22.04 system. For an example, we will switch our hostname to
$ sudo hostnamectl set-hostname linuxconfig
The above command will change the hostname of our Ubuntu 22.04 system to
Upon changing your hostname using the
hostnamectlcommand no system reboot is required to apply the hostname change.
- Next, edit the
/etc/hostsfile to reflect the change by executing the command
sudoedit /etc/hosts. For example, change:
127.0.0.1 localhost 127.0.1.1 ubuntu
127.0.0.1 localhost 127.0.1.1 linuxconfig
- Execute the
hostnamectlcommand 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.
- 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.
- 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.
- 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
linuxconfigin the screenshot below.
- 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 linuxconfig
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.