In this tutorial you will learn how to permanently and without a reboot change a hostname on Ubuntu 20.04 Focal Fossa Linux.
In this tutorial you will learn:
- How to change a hostname on Ubuntu Linux
Software Requirements and Conventions Used
| Category | Requirements, Conventions or Software Version Used |
|---|---|
| System | Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa |
| Software | N/A |
| Other | Privileged access to your Linux system as root or via the sudo command. |
| Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
How to change hostname on Ubuntu 20.04 step by step instructions
Changing the hostname on Ubuntu 20.04 is a rather simple process involving just few steps.
- First, check your current hostname. To do so use either
hostnamectlorhostnamecommand:$ 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: 947a975389d14662b8543c6192fc9658 Boot ID: f9dcef4c25964e3ca7ebcf21e7400a9f Virtualization: oracle Operating System: Ubuntu Focal Fossa Kernel: Linux 5.4.0-9-generic Architecture: x86-64In either case the current hostname of our system is
ubuntu. - Change your hostname to eg.
linuxconfigor any other desired hostname by using thehostnamectlcommand:$ sudo hostnamectl set-hostname linuxconfig
The above command change the hostname of our Ubuntu system to
linuxconfig.NOTE
Upon changing your hostname using thehostnamectlcommand no system reboot is required to apply the hostname change. - Next, edit the
/etc/hostsfile to reflect the change by executing the sudoedit /etc/hosts. For example change:FROM:
127.0.0.1 localhost 127.0.1.1 ubuntu
TO:
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: 947a975389d14662b8543c6192fc9658 Boot ID: f9dcef4c25964e3ca7ebcf21e7400a9f Virtualization: oracle Operating System: Ubuntu Focal Fossa Kernel: Linux 5.4.0-9-generic Architecture: x86-64
