You can easily change hostname in Ubuntu 22.04 (Jammy Jellyfish) by via the Command line or by using Ubuntu’s GUI.
Keep these rules in mind before changing your hostname:
- Your hostname must contain only letters, digits, hyphen and period characters
- The length of the hostname must be between 2-63.
- Hostname must start and end with a number/letter.
Using Command Line
You can use the following command line to set a new hostname for your PC. Here’s how:
Open the Terminal and type the following command:
sudo hostname <Type your new hostname here>
This will change your hostname, but not permanently.
Your hostname will be set to the one you set for the first time the next time your run your PC.
Changing Host Name Permanently
Ubuntu and other Linux distributions save the hostname in /etc/hostname and /etc/hosts files, so in order to change the hostname permanently, you need to edit these files as well.
We will use Ubuntu’s Nano text editor to edit these files. Here’s how:
Open Terminal and type this command :
sudo nano /etc/hostname
You will see your old hostname, change it to a newer one and save the file.
Now you need to edit the /etc/hosts file just as you edited the hostname file, by typing this command:
sudo nano /etc/hosts
This will change your hostname.
Using Ubuntu’s GUI
Ubuntu is very user-friendly in terms of its GUI. You can simply edit your hostname by following these steps:
Open Settings and click on “Details“.
You will see a text field next to “Device name“. This is your hostname.
You can simply type a new one here and your change will be permanent.
Hopefully, you will now be able to easily edit your hostname after this.
A lot of computers could be connected to a network at the same time.
Each computer in the network is called a “host”.
During the Ubuntu installation process, you are asked to name your PC, the name you type there serves as the default hostname for your PC to uniquely identify it in a network.
However, if you get bored of your hostname, you can easily change it by either of the above shared methods.