How To Change Hostname on Ubuntu 22.04 LTS
In this tutorial, we will show you how to change the hostname on Ubuntu 22.04 LTS. For those of you who didn’t know, A computer name (aka hostname) is a label on a computer network that is used to identify the device. This name also differentiates a particular device from others within a local network. Moreover, this name makes an operating system recognizable in the network, thus making the data exchange within the same network easy.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step change of your hostname on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Change Hostname on Ubuntu 22.04 LTS Jammy Jellyfish
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Identify Existing Hostname.
Find out your current system name by running the following command:
hostnamectl
Output:
Static hostname: meilanamaria Icon name: ubuntu-laptop Chassis: laptop Machine ID: 238god3teafr3akz Boot ID: 29intan594944feramona0759229ef0 Operating System: Ubuntu Jammy Jellyfish Kernel: Linux 5.18.0-43-generic Architecture: x86-64
Step 2. Change Hostname on Ubuntu 22.04.
Now run the following command to change the hostname and optionally you can also set the pretty hostname as follows:
hostnamectl set-hostname godetz hostnamectl set-hostname "godetz freakz" --pretty
Next, also /etc/hosts
the file should be edited to successfully change the Ubuntu system name:
nano /etc/hosts
Add the following file:
127.0.0.1 localhost 127.0.1.1 godetz
You’ll need to be sure your hostname conforms to the standards for FQDNs (Fully Qualified Domain Names). The ASCII letters a – z, the digits 0 – 9, and the hyphen (‘-‘) are the only characters acceptable (the first character, however, cannot be a hyphen). You may also find it necessary (or useful) to include the domain name as well, in which case you would then also use periods (dots) to separate the hostname and the domain name (and top-level domain).
Step 4. Verify the Changes.
Run the hostnamectl
command to confirm the hostname change:
hostnamectl
Output:
Static hostname: godetz Icon name: ubuntu-laptop Chassis: laptop Machine ID: 238god3teafr3akz Boot ID: 29intan594944feramona0759229ef0 Operating System: Ubuntu Jammy Jellyfish Kernel: Linux 5.18.0-43-generic Architecture: x86-64
Congratulations! You have successfully changed your hostname. Thanks for using this tutorial for installing the Jenkins on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official Ubuntu website.