Change the hostname (Computer name) in Linux, Ubuntu
A hostname is a computer name which identifies a computer system in a network. The hostname should be a single word with no spaces, may have letters, numbers, periods, or a hyphen and maximum length of 253 characters.
We recommend always using lowercase characters in hostnames to prevent any possible problems or confusion.
Generally, we set up the hostname to the machine during OS setup. You can change your computer’s hostname. In this tutorial, you will learn to change the hostname.
Method 1: Change Hostname on Ubuntu (Reboot Required)
To change the hostname is ubuntu use the below command in the terminal.
sudo nano /etc/hostname
- After using the above command, you will see the current hostname on the nano editor, replace that hostname you wish to change with your new hostname. Save and Exit.
- Here I am changing the hostname from programbr to rocktheworld.
Method 2: Change Hostname on Ubuntu (Reboot not Required)
If you want to change the hostname without rebooting your computer, use the
hostnamectl command. use the following command in the terminal.
hostnamectl set-hostname new-hostname
Don’t forget to replace
new-hostname with your desired hostname. Here I am using programbr as
- You may be required to enter the password to authenticate this step, use your computer-login password.
- If authentication is complete, use
hostnamectlto check the result.
- you will see static hostname with your new hostname.
Ubuntu hostname can be changed via command line as well as GUI. In this tutorial, you learned How to Change Hostname in Ubuntu, Linux via command line. This method should be applicable to all ubuntu versions (16.04 -22.04)