HostName is also referred to as the computer name of your system. It is used to identify the device in various forms of electronic communication in the computer network. Hostname helps you to access local web pages and other authorized data on your system.
In this tutorial, we will show you how to set up the hostname of your computer system using different methods.
Show the Current Hostname of Your System
You can see the hostname of your current system with the following command:
hostname
You should see the following output:
vyompc
Or
hostnamectl
You should see the following output:
Static hostname: vyompc
Icon name: computer-laptop
Chassis: laptop
Machine ID: f431d89b329607cc9bb98cda5e1c7f6f
Boot ID: 512e21aaa55544f4b1380ca90b6279f7
Operating System: Ubuntu 18.04.3 LTS
Kernel: Linux 4.4.0-148-generic
Architecture: x86_64
Or
cat /etc/hostname
You should see the following output:
vyompc
Change the Hostname Temporarily
You can change the hostname of your computer temporarily so it works until next reboot.
You can use the following syntax to change the hostname of your computer temporarily:
hostname new-hostname
For example, change the hostname of your computer from vyompc to testpc temporarily run the following command:
hostname testpc
Next, verify your new hostname with the following command:
hostname
You should see the following output:
testpc
Change Ubuntu Hostname Permanently
There are several ways to change the hostname of your computer permanently.
The simple and easiest way to change the hostname of your computer using the hostnamectl command-line utility.
For example, change the hostname of your computer from vyompc to newpc with the following command:
hostnamectl set-hostname newpc
Next, verify the new hostname with the following command:
hostname
You should see the following output:
newpc
Or
cat /etc/hostname
You should see the following output:
newpc
You can also change the hostname by editing the file /etc/hostname:
nano /etc/hostname
Replace the old hostname with a new one as shown below:
newpc
Save and close the file when you are finished.
Next, you will also need to edit the /etc/hosts file and replace the old computer names to avoid networking issue:
nano /etc/hosts
Replace the old hostname with a new one as shown below:
127.0.1.1 newpc
Save and close the file when you are finished.
Conclusion
In the above guide, you learned how to change the hostname of your computer system. I hope you can now easily change the hostname of your computer system temporarily or permanently.